My dynamic table will not display...
-
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;
}
-
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;
}
What happens if you enable viewstate? let's start there.
-
What happens if you enable viewstate? let's start there.
-
I don't see any difference between the EnableViewState being set to "true" or "false". From reading the MSDN site, I think this needs to be "false" to update the view dynamically.
I finally figured this out. I wasn't approaching the problem correctly. I had to change my ASP code to be an ASP:Placeholder:
Then at the end of my code, instead of assigning the new table to the existing table (which is now gone), I replaced the placeholder control with the new table:
tblBrowserOSTable.Controls.Clear();
tblBrowserOSTable.Controls.Add(newTable);