想用c#对页面一个table中的控件进行遍历,如果是textbox就设置enabled=false,不知道该怎么才能实现

解决方案 »

  1.   

    使用DataTable的Container属性获取IContainer接口。然后循环判断。
      

  2.   

    for(var i=0;i<document.getElementById("table").length;i++)
    {
       if(document.getElementById("table")[i].type=="textbox")
       {
          document.getElementById("table")[i].disabled=true;
       }
    }
    }
    未测试~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      

  3.   

    for(var i=0;i<document.form1.element.length;i++)
    {
       if(document.form1.element[i].type=="textbox")
       {
          document.form1.element[i].disabled=true;
       }
    }
    }
    上面的有问题~这是让整个页面上的textbox的disabled=true;根据这个改一下就可以了~~~~
      

  4.   

    js的我知道,现在需要的是c#的
      

  5.   

    foreach (Control control in table.Controls) {
             if (typeof control is TextBox) { // instanceof ???
                ((TextBox)control).enable = false;
             }
    }自己改改吧,放时间太长了,思路应该没问题
      

  6.   

    table.Controls[0].GetType 这个获得的是tablerow
      

  7.   

    yaoking2000(浪子) ( ) 信誉:100  2006-07-11 16:06:00  得分: 0  
     
     
       table.Controls[0].GetType 这个获得的是tablerow  
     
    我给的只是个例子,具体你的控件放在那个ITEM里面,用table.items[1].Controls[0].GetType .不要认死这个代码
      

  8.   

    private void SetChildControlsState(Control c , bool isDisabled)
        {
            foreach (Control cc in c.Controls)
            {
                if (cc is HtmlControl)
                {
                  HtmlControl  ccc = cc as HtmlControl;
                  if (ccc != null)
                  {
                      ccc.Disabled = isDisabled;
                  }
                }
                if (cc is WebControl)
                {
                    WebControl ccc = cc as WebControl;
                    if (ccc != null)
                    {
                        ccc.Enabled = !isDisabled;
                    }
                }
            }
        }// call
    SetChildControlsState(yourRunatServerTableID,true);
      

  9.   

    //****遍历所有TextBox控件,同时设置TextBox Enabled属性就可以了
            foreach (Control ctrl in Page.Controls)
            {
                if (ctrl is TextBox)
                {
                    TextBox txt = (TextBox)ctrl;
                    if (txt.ClientID == "txt")
                    {
                        txt.Enabled = false;
                    }
                }
            }