A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

本帖最后由 大牙到潍坊 于 2013-12-2 23:17 编辑

如何编程遍历页面上所有TextBox控件并给它赋值为string.Empty?
,求大神

评分

参与人数 1技术分 +1 收起 理由
V_John + 1

查看全部评分

3 个回复

倒序浏览
foreach遍历control 用gettype获取控件类型判断是不是textbox  是就赋值

评分

参与人数 1技术分 +1 收起 理由
V_John + 1

查看全部评分

回复 使用道具 举报
  1. foreach (System.Windows.Forms.Control control in this.Controls)
  2. {
  3.     if (control is System.Windows.Forms.TextBox)
  4.     {
  5.         System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control;
  6.         tb.Text = String.Empty;
  7.     }
  8. }

  9. function BianLi()
  10. {
  11.         var t=document.getElementsByTagName("input");
  12.         for(var i=0;i<t.length && t[i];++i)
  13.         {
  14.             if(t[i].type=="text")
  15.             {
  16.                 t[i].value="";
  17.             }
  18.         }
  19. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
V_John + 1

查看全部评分

回复 使用道具 举报
foreach(Control con in this.Controls)
{
      if(con is TextBox)
      {
           (con as TextBox).Text = string.Empty;
      }
}

评分

参与人数 1技术分 +1 收起 理由
V_John + 1

查看全部评分

回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马