I have a table that is being dynamically generated based on selected fields from my form. However, after I have modified the table, I can't get it to display on the web page. What am I doing wrong or what else do I need to do to get the page to display correctly? ASP place holder:
(I have tried EnableViewState="false" too.) C# code:
protected void MakeBrowserOSTable(DataTable dtContents)
{
int numRows = dtContents.Rows.Count;
int numCells = dtContents.Columns.Count;
Table newTable = new Table(); // The table can totally change depending on the
// selection - so I want to rebuild it each time.
if ((numCells <= 0) || (numRows <= 0))
{
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.Add(new LiteralControl("Please choose a platform"));
row.Cells.Add(cell);
newTable.Rows.Add(row);
}
else
{
foreach (DataRow r in dtContents.Rows)
{
TableRow row = new TableRow();
for (int c = 0; c < numCells; c++)
{
TableCell cell = new TableCell();
if (c == 0)
{
Label lbl = new Label();
lbl.Text = (string)r\[c\];
lbl.Text = lbl.Text.Trim();
cell.Controls.Add(lbl);
}
else
{
//add other controls here
}
row.Cells.Add(cell);
}
newTable.Rows.Add(row);
}
}
tblBrowserOSTable = newTable;
}