Creating html table dynamically
I have a for loop (dataset returns 10 records) . I need to keep creating html tables till a certain condition meet. e.g: if loop count is 10 then 10 html tables will be generated with 3 rows and 4 cols displaying text values from my dataset. can anyone help me how to create html tables dynamically using for loop, and how to add multiple cols and rows in one table and then add text in rows and cols from my dataset.
thanks
Re: Creating html table dynamically
this might help
for (int k = 0; k < 4; k++)
{
HtmlTable table1 = new HtmlTable();
table1.ID = "table1" + k;
for (int i = 1; i < 4; i++)
{
HtmlTableRow row = new HtmlTableRow();
row.ID = "row" + i;
for (int j = 1; j < 4; j++)
{
HtmlTableCell cell = new HtmlTableCell();
cell.ID = "cell" + j;
cell.InnerHtml = "cell" + i + j;
row.Cells.Add(cell);
}
table1.Rows.Add(row);
}
table1.CellPadding = 2;
table1.CellSpacing = 2;
table1.BorderColor = "Green";
table1.Border = 2;
}
Re: Creating html table dynamically
Please us the editor to format your code in more readable segments using a formatting tag.
Examples:
[code]
for (int j = 1; j < 4; j++)
{
HtmlTableCell cell = new HtmlTableCell();
cell.ID = "cell" + j;
cell.InnerHtml = "cell" + i + j;
row.Cells.Add(cell);
}
[/code]
[php]
for (int j = 1; j < 4; j++)
{
HtmlTableCell cell = new HtmlTableCell();
cell.ID = "cell" + j;
cell.InnerHtml = "cell" + i + j;
row.Cells.Add(cell);
}
[/php]
[HIGHLIGHT="VB.NET"]
for (int j = 1; j < 4; j++)
{
HtmlTableCell cell = new HtmlTableCell();
cell.ID = "cell" + j;
cell.InnerHtml = "cell" + i + j;
row.Cells.Add(cell);
}
[/HIGHLIGHT]
Which Formats your text like so:
Code:
for (int j = 1; j < 4; j++)
{
HtmlTableCell cell = new HtmlTableCell();
cell.ID = "cell" + j;
cell.InnerHtml = "cell" + i + j;
row.Cells.Add(cell);
}
PHP Code:
for (int j = 1; j < 4; j++)
{
HtmlTableCell cell = new HtmlTableCell();
cell.ID = "cell" + j;
cell.InnerHtml = "cell" + i + j;
row.Cells.Add(cell);
}
VB.NET Code:
for (int j = 1; j < 4; j++)
{
HtmlTableCell cell = new HtmlTableCell();
cell.ID = "cell" + j;
cell.InnerHtml = "cell" + i + j;
row.Cells.Add(cell);
}