HtmlTable,HtmlTableRow,HtmlTableCell - 创建thead,tbody和tfoot

Jac*_*ack 7 html c#

我正在使用c#ASP .Net,HtmlTable,HtmlTableRow,HtmlTableCell来创建表.

例如......我需要让一些细胞被包裹 <tfoot> and </tfoot>

我试图用HtmlGenericControl来将这些带有标签"tfoot"的单元格包装到HtmlTable但是它不起作用.

我知道HtmlTableCell可以在构造函数"th"中用于"thead"和"td"用于tbody.但是我需要用实际的"thead"和"tbody"包裹它们.

有什么建议??

JR *_*aid 22

这是如何(下面).使用的所有类都在System.Web.UI.HtmlControls中.

        TableRow headerRow = new TableHeaderRow();
        TableRow row2 = new TableRow();
        TableRow row3 = new TableFooterRow();
        Table table = new Table();

        var cell1 = new TableCell();
        headerRow.TableSection = TableRowSection.TableHeader;
        cell1.Text = "Header";
        headerRow.Cells.Add(cell1);

        var cell2 = new TableCell();
        cell2.Text = "Contents";
        row2.Cells.Add(cell2);

        var cell3 = new TableCell();
        cell3.Text = "Footer";
        row3.Cells.Add(cell3);
        row3.TableSection = TableRowSection.TableFooter;


        table.Rows.Add(headerRow);
        table.Rows.Add(row2);
        table.Rows.Add(row3);
        this.Controls.Add(table);
Run Code Online (Sandbox Code Playgroud)