就是弄个置零的按钮,点一下,然后所有的textbox一起归零

解决方案 »

  1.   

    拖一个按钮,在这个按钮的click事件里面,将所有的textbox的text属性设置为“”
    是这个意思不?
      

  2.   

    //这里页面所有textbox清空的方法
    function SetTextBox()
    {
     var txts = document.getElementsByTagName('INPUT');
     for(var i = 0; i < txts.length; i++)
     {
      if (txts[i].type.toUpperCase() == 'TEXT')
      {
         txts[i].value = "";
      }
     }}//按钮的onclick="SetTextBox()"
    //如果是服务器按钮 OnClientClick="SetTextBox()"
      

  3.   

    可以拉一个<input />onclick事件调用一个JavaScript
    用JavaScript遍历页面上的TextBox设置其值为:0
      

  4.   

    LZ... 方法就是我3楼给你的。。手写的。。有小错见谅。。PS:你记得要结帖啊。。你看你那结帖率。。惨不忍睹啊。。
      

  5.   

    foreach (var i in Controls)
    {
        TextBox tb = i as TextBox;
        if (tb != null) tb.Text = "0";
    }
      

  6.   

    foreach (Control aa in Page.Controls)
            {
                if (aa is TextBox )
                {
                    TextBox tb = (TextBox )aa;
                    tb.Text = "";
                  }
            }
      

  7.   

    递归        public static void ResetTextBox(Control control)
            {
                if (control.HasChildren)
                {
                    foreach (Control subControl in control.Controls)
                    {
                        if (subControl is TextBox)
                            (subControl as TextBox).Text = string.Empty;
                        else
                            ResetTextBox(subControl);
                    }
                }            
            }
      

  8.   

    问题问的不够详细,也没说是winform还是WPF程序,还是asp.net.还搞了个怎么结贴,哥们好无语。。
      

  9.   

    用遍历吧   将所有的textbox的值都=""
      

  10.   

    后台就遍历 Controls
    js就document.getElementByTagName()
      

  11.   

    public static void clear(Control.ControlCollection  cs)
            {
                foreach (Control c in cs)
                {
                    if (c is TextBox)
                    {
                        c.Text = "";
                    }
                 }
            }
      

  12.   


    这个不是递归吧,如果subcontrol的control的control里还有textbox呢?
      

  13.   


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

  14.   

       protected void SetEmpty()
            {
                try
                {
                    foreach (Control ctrl in pnlIn.Controls)
                    {
                        Label lable = new Label();
                        if (ctrl.GetType() != lable.GetType())
                        {
                            ctrl.Text = 0;
                        }
                    }
                }               
            }
      

  15.   

    如果是web的话,加一个 input type = "reset"
      

  16.   


    foreach(Control c in this.Controls)
    {
         if(c is TextBox)
         {
             (c as TextBox).Text = "0";
         }   
    }
    除了这个还可以用容器,当然窗体也是个容器.方法多了
      

  17.   

    有控件容器类吧  foreach 一下应该开一吧
      

  18.   

    遍历窗体中所有的butoon控件,楼上的都讲完了
      

  19.   

    private void button1_Click(object sender, EventArgs e)
            {
                
                foreach (object item in this.Controls)
                {
                    if (item is TextBox)
                    {
                        TextBox tt = item as TextBox;
                        tt.Text = "";
                    }
                    else
                    {
                        continue;
                    }
                }
            }我这个方法比较简单,已经试过, 我是新手,勿笑.
      

  20.   

    可以把所有textbox引用到一个数组里然后foreach循环清空把?
      

  21.   

    最简单的:如果是web的话,加一个 input type = "reset"
      

  22.   

    我上面所有用 foreach的 +++++
      

  23.   

    这个用脚本做把速度比较快       用JS或者JQuery遍历文本   赋值为""
    $(":input").foreach(function(i){
        $(this).val("");
    });
      

  24.   

    方法太多了,上面举出了用JS的方法,和c#控件遍历的方法
      

  25.   

    如果是WinForm,那么就遍历一下窗体所有的控件
    如果是textBox就把它置为空或者为0,就OK了
      

  26.   


    ///声明:本人新手一名
    ///本人测试代码 protected void Button1_Click(object sender, EventArgs e)
        {
            foreach(Control aa in Page.Controls )
                if (aa is TextBox)
                {  
                    TextBox tb = (TextBox)aa; 
                    tb.Text= " ";
                }
        }怎么点击Button1  没反应 求解。谢谢大虾们。。
      

  27.   

    我从网上找到了一个例子,绝对适合LZ
    遍历页面上所有的TextBox控件并将其设置为空值
      

  28.   

    用foreach的注意,最好习惯吧它看成只读迭代