Add a Panel on the page
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
and then create and add the table to panel
Table table = new Table();
table.BorderStyle = BorderStyle.Solid;
//Add Header Row
TableRow row = new TableRow();
TableHeaderCell headerCell = new TableHeaderCell();
headerCell.Text = "Item";
row.BackColor = Color.Green;
row.Controls.Add(headerCell);
headerCell = new TableHeaderCell();
headerCell.Text = "Price";
row.Controls.Add(headerCell);
table.Controls.Add(row);
//Add DataRow
row = new TableRow();
TableCell cell = new TableCell();
cell.Text = "Shirt";
row.Controls.Add(cell);
cell = new TableCell();
cell.Text = "200";
row.Controls.Add(cell);
row.BackColor = Color.Yellow;
table.Controls.Add(row);
//Add Colspan Row
row = new TableRow();
row.BorderStyle = BorderStyle.Solid;
cell = new TableCell();
cell.Text = "Colspan Row";
cell.ColumnSpan = 2;
row.Controls.Add(cell);
row.BackColor = Color.Brown;
table.Controls.Add(row);
//Add DataRow
row = new TableRow();
cell = new TableCell();
cell.Text = "Tie";
row.Controls.Add(cell);
cell = new TableCell();
cell.Text = "30";
row.Controls.Add(cell);
table.Controls.Add(row);
row.BackColor = Color.Beige;
Panel1.Controls.Add(table);
Item | Price |
Shirt |
200 |
Colspan Row |
Tie |
30 |