相关疑难解决方法(0)

通过asp.net中的TextBoxes进行迭代 - 为什么这不起作用?

我有两种方法试图迭代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);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

和"不工作"代码:

List<string> list = new List<string>();

    foreach (Control control in Controls)
    {
        TextBox textBox = control as TextBox;
        if (textBox != null)
        {
            list.Add(textBox.Text);
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# asp.net textbox

7
推荐指数
1
解决办法
5457
查看次数

标签 统计

asp.net ×1

c# ×1

textbox ×1