我在使用了118个textbox的值作为一个经费申请的表单提交的时候,突然意识到:
   string[] a=new arry[];
   a[0]=textbox1.text;
   a[1]=textbox2.text;
  ...
  ...
  ...
100个之后我不知道到底哪个存放的什么值了。
 狂晕之后,寻求
  for(int i=1;i<=118;i++)
{
     a[i]=textbox[i].text;}
大家知道,这是不可能的!
请教大虾,这件事情又没有考虑到?

解决方案 »

  1.   

    foreach(TextBox box in this.Controls)
    {
      a[box.ID.SubString(6,box.ID.Length-1)] = box.Text;
    }不知道行不
      

  2.   

    ArrayList arrText = new ArrayList();
    foreach( System.Web.UI.Control control in this.Controls )
    {
       if( control.GetType() is System.Web.UI.HtmlControls.HtmlForm )
       {
           foreach( System.Web.UI.WebControls.TextBox txtControl in control.Controls )
           {
               arrText.Add( txtControl.Text );
           }
       }}
      

  3.   

    试试:
     
    for(int i=1;i<=118;i++)
    {
         a[i] = ((TextBox)FindControl(textbox[i])).Text;}
      

  4.   

    sorry: 上面应该改为如下:试试:
     
    for(int i=1;i<=118;i++)
    {
         a[i] = ((TextBox)FindControl("textbox" + i.ToString())).Text;}
      

  5.   

    findcontrol 能解决,但不是那样子使用。不过非常感谢!提醒了我