如何使用 ASP.NET 表控件方法(使用、Table、TableRow、TableColumn、TableHeader 等)从 CodeBehind 创建表

苏里亚迪巴苏

我需要创建一个表,这将有一个头和像这样多个复选框。有人可以提供一些参考,以便我了解 ASP.NET 表控件的工作原理。我已经彻底阅读了 MSDN 博客。所以,但我无法理解。如果有人能详细解释一下,我会很高兴。

永远学习

无法看到您的图片,因为工作阻止了 imgur.com,所以希望这会有所帮助。我们使用这样的东西来创建自定义 ListView 控件。但是由于您不能使用 GridView,我建议在页面上放置一个 PlaceHolder 控件。创建表后,将其添加到 PlaceHolder。

    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);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档