Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

c# - HtmlTable, HtmlTableRow, HtmlTableCell - creating thead, tbody and tfoot

I'm working with c# ASP .Net, HtmlTable, HtmlTableRow, HtmlTableCell to create a table.

for example... i need to have some cells to be wrapped by <tfoot> and </tfoot>

i tried to do it with HtmlGenericControl to wrap these cells with the tag "tfoot" to the HtmlTable but it didn't work.

i know that HtmlTableCell can have in the constructor "th" for "thead" and "td" for tbody. but i need them to be wrapped with the actual "thead" and "tbody".

Any Suggestions??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is how (below). All classes used are in System.Web.UI.WebControls.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...