Click here to Skip to main content
15,908,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,

i am creating a timesheet project for that i need to create n number of grid views based on the topic groupings from database.

Topic\Day 1 2 3 4 .....
Topic 1
Topic 2
Topic 3

Could you please help me on this
Posted
Comments
AshishChaudha 30-Jun-12 15:13pm    
what you have done??
bbirajdar 30-Jun-12 15:25pm    
Any efforts ?
Sandeep Mewara 1-Jul-12 4:53am    
Help with what? Where are you stuck?

Your question is pretty brief, but if if i think i understand what you want to do, you could try this in the codebehind:

C#
List<string> ThisIsYourList = new List<string>();
Gridview1.DataSource = ThisIsYourList;
Gridview1.DataBind();


f you want to add a dropdownlist to every row, you need to add an itemtemplate to your gridview like this:

XML
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"/>
</ItemTemplate>
</asp:TemplateField>


You add this itemtemplate anywhere between the tags of your gridview.
 
Share this answer
 
This method will help you to create the Grid View dynamically

pass the number of groups to the method as an input

private void GenerateGridview(int groupCount){
        int colsCount =1; 
        //Creat the Table and Add it to the Page
        Table table = new Table();
        table.ID = "Table1";
        Page.Form.Controls.Add(table);

        // Now iterate through the table and add your controls 
        for (int i = 0; i < groupCount; i++){
            TableRow row = new TableRow();
            for (int j = 0; j < colsCount; j++){
                TableCell cell = new TableCell();
                Gridview tb = new Gridview();

                // Set a unique ID for each Gridview added
                tb.ID = "GridviewRow_" + i + "Col_" + j;
                // Add the control to the TableCell
                cell.Controls.Add(tb);
                // Add the TableCell to the TableRow
                row.Cells.Add(cell);
            }

            // Add the TableRow to the Table
            table.Rows.Add(row);
        }
}


Mark as answer, if it resolved your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900