[ACCEPTED]-c# create thead and tbody-html-table

Accepted answer
Score: 21

Here a sample code that creates a THead, TBody 5 and TFooter.

You can basically always use 4 the TableRow object just reset the TableSection 3 property.

    Table table = new System.Web.UI.WebControls.Table();
    TableRow tableRow;
    TableCell tableCell;

    tableRow = new TableRow();
    tableRow.TableSection = TableRowSection.TableHeader;
    tableCell = new TableCell();
    tableCell.Text = "HEADER";
    tableRow.Cells.Add(tableCell);
    table.Rows.Add(tableRow);

    tableRow = new TableRow();
    tableRow.TableSection = TableRowSection.TableBody;
    tableCell = new TableCell();
    tableCell.Text = "BODY";
    tableRow.Cells.Add(tableCell);
    table.Rows.Add(tableRow);

    tableRow = new TableRow();
    tableRow.TableSection = TableRowSection.TableFooter;
    tableCell = new TableCell();
    tableCell.Text = "FOOTER";
    tableRow.Cells.Add(tableCell);
    table.Rows.Add(tableRow);

    plhTest.Controls.Add(table);

Although I would suggest building 2 the table in direct html and appending to 1 page.

Score: 7

TableRow is basically tbody.

To make a thead section, use 3 the TableHeaderRow class instead of a TableRow class.

(There 2 is also, btw, TableFooterRow if you want to implement 1 tfoot.

Score: 0
var row = new TableHeaderRow() { TableSection = TableRowSection.TableHeader };
table.Rows.Add(row);

should do the trick

0

More Related questions