以编程方式创建表,在其中输入值,检索全部内容
当我去解析表时,我以编程方式创建的所有内容都丢失了......
我一定忘记了一些东西,因此它丢失了我以编程方式构建的所有内容(我只得到了表的外壳)。
有什么想法吗?
如果我在以编程方式创建表后将表放入会话对象中,那么它会起作用,除非用户输入的所有值显然不会在那里。
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);
}
}
}
}
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 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);
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是 ASP.NET 生命周期的另一种情况。如果您动态创建控件,它们将在视图状态中不可用,除非您重新创建它们。即便如此,我也不知道这些价值观会持续下去。
(我认为他们可能会这样做。我已经有一段时间没有与这个特殊的 Web Forms 夸克作斗争了。)
查看此问题了解更多信息。
为什么要动态创建表?你能使用 asp:GridView 吗?
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?