如上图,上图中有6个textbox控件,但是程序中不一定是6个,有可能4,5,7,9.。等等!
请问高手怎么获取啊?

解决方案 »

  1.   


    int i = 0;
    ArrayList al = new ArrayList();
            foreach (Control c in Page.Controls)
            {
                if (c.GetType().Name == "HtmlForm")
                {
                    foreach (Control c1 in c.Controls)
                    {
                        if (c1.GetType().Name == "TextBox")
                        {
                            al.Add(((TextBox)c1).ID); //将TextBox的ID保存在一个集合中
                            i++;  //控件个数
                        }
                    }
                }
            }
      

  2.   

    int n = (from x in this.Controls where x.GetType() == typeof(TextBox) select x).Count();
      

  3.   

      
    foreach (Control control in this.Controls)
                {
                    if (control is TextBox)
                    {
                        TextBox txtBox = (TextBox)control;
                        //这里可以取出TextBox的属性,名字这些
                    }
                }
    www.xiaoniusoft.com
      

  4.   

    int i = 0;
    foreach(Contorl c in this.Contorls)
    {
      i ++;
    }