我有2个方法我尝试遍历所有我的文本框在一个asp.net页面。第一个工作,但第二个没有返回任何东西。有人可以向我解释为什么第二个不工作?在asp.net中迭代文本框 - 为什么这不起作用?
该工程确定:
List<string> list = new List<string>();
foreach (Control c in Page.Controls)
{
foreach (Control childc in c.Controls)
{
if (childc is TextBox)
{
list.Add(((TextBox)childc).Text);
}
}
}
和“不工作”的代码:
List<string> list = new List<string>();
foreach (Control control in Controls)
{
TextBox textBox = control as TextBox;
if (textBox != null)
{
list.Add(textBox.Text);
}
}
在第二批代码中,控件是否包含任何东西? – brumScouse 2010-11-03 22:05:44