How to create table dynamically in c#

dude, you have to tell the requirement or the expected output. there is no purpose listed here. for example, i could tell you just do Response.Write(yourtablestr); and it would technically be dynamic.

Commented Oct 28, 2012 at 7:18

Sorry, I do not understand your question. May you please describe what you are exactly trying to do? :)

Commented Oct 28, 2012 at 7:19 I have written HTml table in quetion thats i have to create dynamically in c# Commented Oct 28, 2012 at 7:22

3 Answers 3

You can try this code to create table.

First place this markup in your aspx page like

Then Try This code in Page_Load like

protected void Page_Load(object sender, EventArgs e)

Or You can try this, by storing cell values in 2D Array like

protected void Page_Load(object sender, EventArgs e) < String[,] cellValues = < < "1", "2", "3" >, < "a", "b", "c" >, < "m", "n", "o" >>; HtmlTableRow row = new HtmlTableRow(); HtmlTableCell cell = new HtmlTableCell(); cell.ColSpan = 3; cell.InnerText = "Record 1"; row.Cells.Add(cell); tableContent.Rows.Add(row); for (int i = 0; i < cellValues.GetLength(0); i++) < row = new HtmlTableRow(); for (int j = 0; j < cellValues.GetLength(1); j++) < cell = new HtmlTableCell(); cell.InnerText = cellValues[i, j]; row.Cells.Add(cell); >tableContent.Rows.Add(row); > row = new HtmlTableRow(); cell = new HtmlTableCell(); HtmlInputButton input = new HtmlInputButton(); input.ID = "Button1"; input.Value = "button"; cell.ColSpan = 3; cell.Controls.Add(input); row.Cells.Add(cell); tableContent.Rows.Add(row); >