本文介绍了根据数据库中的数据和每月的天数动态创建网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为此创建一个时间表项目,需要根据数据库中的主题分组创建n个网格视图.
Topic \ Day 1 2 3 4 .....
主题1
主题2
主题3
您能帮我解决这个问题吗?
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
推荐答案
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:
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
您可以在gridview的标签之间的任意位置添加此itemtemplate.
You add this itemtemplate anywhere between the tags of your gridview.
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.
这篇关于根据数据库中的数据和每月的天数动态创建网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!