Programmatically create table, enter values in it, retrieve the entire contents
When I go to parse through the table, all the stuff I created programmatically is missing...
I must be forgetting something so that it's losing all the stuff that I built programmatically (I am 开发者_JAVA百科only getting the shell of the table).
Any ideas?
If I put the table in a Session object after I programmatically create it then it works except all the values the user enters will not be there obviously.
protected void btnSave_Click(object sender, EventArgs e)
{
SaveMainGrid(tblCC);
// SaveMainGrid((System.Web.UI.WebControls.Table)Session["tblMain"]);
}
private void SaveMainGrid(Control control)
{
foreach (Control ctrl in control.Controls)
{
if (ctrl is RadNumericTextBox)
{
RadNumericTextBox t = ctrl as RadNumericTextBox;
}
else
{
if (ctrl.Controls.Count > 0)
{
SaveMainGrid(ctrl);
}
}
}
}
This is likely another case of asp.net lifecycle. If you dynamically create controls, they aren't going to be available in the viewstate unless you recreate them. Even then, I don't know that the values would be persisted.
(I think they might. It's been a while since I fought this particular Web Forms quark.) Check this question out for more info.
Why are you creating the table dynamically? Can you use an asp:GridView?
精彩评论