桂林网站建设
您的位置: 首页> asp.net

我要叫喊

学习本类知识需要注意某些知识点,它们之间有些关联

      技术文档
      本站业务
      本类热点
  1. C#加密解密方法...
  2. 无法加载 DLL“...
  3. ASP.NET(C#)中...
  4. 省市连动菜单,省...
  5. DataList使用,网...
  6. DateTime.ToStrin...
  7. asp.net中的日历控...
  8. win2003服务器asp对...
  9. asp.net C# cookie清...
  10. ASP读写cookie的...
ASP.NET(C#)中遍历所有控件(winform及asp.net)

for (int i = 0; i < this.Controls.Count; i++)
{
    foreach (System.Web.UI.Control control in this.Controls[i].Controls )
   {
        if (control is TextBox)
            (control as TextBox).Text = "";
    }
}
或者
foreach(Control cl in this.Page.FindControl("Form1").Controls)
{
    if(cl.GetType().ToString()=="System.Web.UI.WebControls.TextBox")
   {
        ((TextBox)cl).Text="";
    }
}

 

有一个winform   ,是个mdicontainer,上有很多个button,请问怎样得到这些button的集合?  
  ------------------------------------------------------------------------------  
  要考虑其他的容器控件,比如说Panel  
   
  最简单的情况如下  
  foreach(Button   b   in   this.Controls)  
  {  
   
  }  
   
  但是如果有Panel还要对Panel做一个循环  
   
  所以最好做一个递归的方法  
  如下:  
   
   
  private   void   FindButton(Control   c)  
  {  
  if(c   is   Button)  
  {  
  MessageBox.Show("Button!");  
  }  
  if   (c.Controls   !=   null)  
  {  
  foreach(Control   x   in   c.Controls)  
  {  
  FindButton(x);  
  }  
  }  
  }  
   
  在窗体里面调用  
  this.FindButton(this);