如何使用 ASP.NET 表控制方法(使用,表,表行,表列,表头等)从代码隐藏创建表



我需要创建一个表,该表将有一个标题和"喜欢"多个复选框。有人可以给一些参考,以便我了解 ASP.NET 表控件的工作原理。我已经浏览了MSDN博客。所以,但我无法理解。如果有人能详细解释,我会很高兴。

看不到您的图像,因为工作块 imgur.com,所以希望这有所帮助。 我们使用类似的东西来创建自定义列表视图控件。 但由于您不能使用 GridView,我建议在页面上放置一个占位符控件。 创建表后,将其添加到占位符。

Table t = new Table();
TableHeaderRow th = new TableHeaderRow();
//add the header row to table t
t.Rows.Add(th);
//add three columns to the header row with a label for text
for (int i = 0; i < 3; i++)
{
TableCell td = new TableCell();
Label lb = new Label();
lb.Text = "Header Label: " + i.ToString();
td.Controls.Add(lb);
th.Cells.Add(td);
}
//add the rows, say you need five
for (int i = 0; i < 5; i++)
{
TableRow tr = new TableRow();
//add three columns to the table row with a checkbox
for (int i = 0; i < 3; i++)
{
//add the cells with a checkbox
TableCell td1 = new TableCell();
CheckBox cb = new CheckBox();
cb.Text = "CheckBox: " + i.ToString() + "_" + j.ToString();
td.Controls.Add(cb);
tr.Cells.Add(td1);
}
t.Rows.Add(tr);
}
placeHolder.Controls.Add(t);

最新更新