我想遍历界面上的textbox值,并把取出的值累加起来,各位高手帮忙看下,以为是新手,恳请贴源码,做了几天了,还没搞定,真是急!!!!

解决方案 »

  1.   

    这样遍历界面上的textbox值       
     foreach (Control cor in this.Page.Controls)
            {
                if (cor.GetType().Equals(TextBox))
                {
                    string str = "";
                    str += (cor as TextBox).Text;
                }
            }
      

  2.   

    StringBuilder sb=new StringBuilder();
                foreach (Control ctr in this.Controls)
                {
                    if (ctr.GetType().ToString()=="System.Windows.Forms.TextBox")
                    {
                        if (ctr.Text.Trim().Length != 0)
                        {
                            sb.Append(ctr.Text);
                        }
                    }
                }
                if (sb.ToString().Trim().Length != 0)
                {
                    MessageBox.Show(sb.ToString());
                }
      

  3.   


            string value = "";
            foreach (Control c in Controls)
            {
                if (c is TextBox)
                {
                    value += ((TextBox)c).Text;
                }
            }
      

  4.   


    string s = "";
    foreach (Control c in this.Controls)
    {
       if (c.GetType().Name.Equals("TextBox"))
       {
          s += c.Text;
       }
    }
      

  5.   

    这种计算我就用在客户端上做了 var txt = document.getElementsByTagName("input");
    var aa = "";
    for(var i=0;i<txt.length;i++)
    {
       if(txt[i].type=='text')
       {
           aa = txt[i].value+aa;
       }
    }然后把aa赋值给一个隐藏控件  服务器上直接取
      

  6.   

        
        string result="";
        string FindTextBox(Control ctl)
        {
            foreach (Control parent in ctl.Controls)
            {
                foreach (Control c in parent.Controls)
                {
                    if (c.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
                        result = ((TextBox)c).Text;
                    FindTextBox(parent);
                }            
            }
            return result;
        } 
    手写的,没有测试过,你自己试试
      

  7.   

    用System.Text.StringBuilder就可以了是字符串变量。