Pages

Monday, January 9, 2012

Creating dynamic HTML table

Set-up the table:
Table tbl = new Table();
tbl.CssClass = "grdVwTable"; // the css class
tbl.CellSpacing = 0; // the cellspacing
tbl.CellPadding = 2; // the cellpadding
tbl.GridLines = GridLines.Both; // set the gridlines/borders


Create the row and column for the table head:
TableRow tr = new TableRow();
TableHeaderCell th1 = new TableHeaderCell();
th1.Text = "Sample text";
tr.Cells.Add(th1);


Add the row created to the table:
tbl.Rows.Add(tr);


Set which row is in the thead
tbl.Rows[0].TableSection = TableRowSection.TableHeader;


Create the row and column for the table body:
TableRow trows = new TableRow();
TableCell tc1 = new TableCell();
tc1.Text = confidential;
trows.Cells.Add(tc1);


Add the row created to the table:
tbl.Rows.Add(trows);