نحوه ساخت جدول Table داینامیک در #C
ابتدا در بخش Html کد زیر را قرار می دهیم/
<asp:PlaceHolder ID="Place" runat="server"></asp:PlaceHolder>
سپس در بخش کد نویسی سی شارپ کد زیر را قرار می دهیم
HtmlTable table = new HtmlTable();
table.Border = 1;
table.CellPadding = 3;
table.Width = "100%";
// Populate the HtmlTable control by adding rows to it.
for (int rowcount = 0; rowcount < objobjCookiefieldList.Count(); rowcount++)
{
// Create a new HtmlTableRow control.
HtmlTableRow row = new HtmlTableRow();
// Add cells to the HtmlTableRow control.
for (int cellcount = 0; cellcount < 2; cellcount++)
{
// Define a new HtmlTableCell control.
HtmlTableCell cell;
// Create table header cells for the first row.
if (rowcount <= 0)
{
cell = new HtmlTableCell("th");
}
else
{
cell = new HtmlTableCell();
}
// Create the text for the cell.
if (cellcount==0)
{
cell.Controls.Add(new LiteralControl(objobjCookiefieldList[rowcount].CookieFieldName));
}
else
{
cell.Controls.Add(new LiteralControl(objobjCookiefieldList[rowcount].CookieFieldValue));
}
// Add the cell to the HtmlTableRow Cells collection.
row.Cells.Add(cell);
}
// Add the row to the HtmlTable Rows collection.
table.Rows.Add(row);
}
// Add the control to the Controls collection of the
// PlaceHolder control.
Place.Controls.Clear();
Place.Controls.Add(table);