如何获取多个文本框的值.net
页面中的textbox的个数不确定,至少有5个,cs文件中怎样循环获取这些文本框的值,并保存到一个变量中
------解决方案--------------------C# code
  string temp_str = string.Empty;
            foreach (Control cl in this.Form.Controls)
            {
                if (cl is TextBox)
                {
                    TextBox tb = cl as TextBox;
                    temp_str += tb.Text;
                }
            }
------解决方案--------------------
C# code
string[] result = Controls.OfType<TextBox>().Select(x => x.Text).ToArray();
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
LINQ+拉姆达
------解决方案--------------------
[Quote=引用:]
C# code
string[] result = Controls.OfType<TextBox>().Select(x => x.Text).ToArray();
[/Quote
这个不错
------解决方案--------------------
2楼的回答好 学习了
------解决方案--------------------
  //TextBox btox = (TextBox )Master.FindControl("TextBox1 ");
  string temp_str = string.Empty;
           foreach (Control cl in  Master.Controls)
           {
               if (cl is TextBox)
               {
                   TextBox tb = cl as TextBox;
                   temp_str += tb.Text;
               }
           }
试一下这个行不行 我没有测试
------解决方案--------------------
foreach(Control con in Master.Controls)
{
     if(con is TextBox){
       TextBox tb = cl as TextBox;
    }
}
------解决方案--------------------
在定义的时候定义name 或ID