foreach(TextBox tb in.....
具体该如何写,肯请指点

解决方案 »

  1.   

    for (int i = 0; i < this.Controls.Count; i ++)
    {
    if (this.Controls[i] is TextBox)
    {
    (this.Controls[i] as TextBox).Text = "";
    }
    }
      

  2.   

    to:回复人: xuchi(赤色六芒星) ( ) 信誉:99 
    请问这个是不是C#的啊?
      

  3.   

    我好像看到过的是用foreach的,还请帮忙写一个,谢谢
      

  4.   

    foreach (Control ctl in Controls)
    {
      if (ctl is TextBox)
      {
        ctl.Text = string.Empty;
      }
    }
      

  5.   

    Dim objButton As Control               For Each objButton In Controls
               If TypeOf(objButton) is textBox Then
                  objButton.Text = ""
               End If
           Next
      

  6.   

    public void settextbox(Control container)
    {
      if (container == null  ) return ;
      if (container is TextBox ) 
       {
         container.text="";
          return;
       }
         if (container.Controls.Count > 0 )
        {
    for (int i=0; i < container.Controls.Count; i++)
    {
      settextbox(container.Controls[i]);
    }
        }
    }
      

  7.   

    foreach (Control control in Controls)
    {
      if (control is TextBox)
      {
        ctl.Text = "";
      }
    }
      

  8.   

    我想这样应该没错,你试试看:
    string ControlType;  
    foreach (Control Ctl in this.Controls)
    {
      ControlType=Ctl.GetType().ToString();
      if (ControlType=="System.Windows.Forms.TextBox")
         ((TextBox)Ctl).Text=""; 
    }
    其中:this代表包含文本框的容器。
      

  9.   

    lljfl(Dos)的什么意思?
    控件里的TextBox?
      

  10.   

    lljfl(Dos)的什么意思?
    控件里的TextBox?因为不仅form可以包含textbox,form里面的groupbox,panel也可能包含textbox.
      

  11.   

    为什么我放在代码里,都没有效果啊?你将我上面的代码copy到你的form,然后调用settextbox(this) this指当前form
      

  12.   

    string ControlType;  
    foreach (Control Ctl in this.Controls)
    {
      TextBox t = Ctrl as TextBox;
      if(t != null)
      {
          t.Text = "";
      }
    }
    这样写的效率要高一些.
      

  13.   

    foreach (Control Ctl in this.Controls)
    {
      if (Ctl is TextBox)
      {
        (TextBox)Ctl.Text = "";
      }
    }
      

  14.   

    这样肯定对int nControls = this.Controls.Count;
    for (int i = 0; i < nControls; i++)
    {
    foreach (System.Web.UI.Control control in this.Controls[i].Controls )
    {

    if (control is TextBox)
    (control as TextBox).Text = "";
    }
    }
      

  15.   

    foreach(Control cl in this.Page.FindControl("Form1").Controls)
    {
    if(cl.GetType().ToString()=="System.Web.UI.WebControls.TextBox")
    {
    ((TextBox)cl).Text="";
    }
    }
      

  16.   

    foreach是不能这样使用的
    它只能查找不能副值
    所以你只能使用for
    后其他的
    for(int i=0;i<n;i++)
      textBoxi.Text=null;
    这样就行了