我是用下面的方法把整个页面Disabled掉
foreach (Control c in control.Controls)
{
string cType = c.GetType().Name;
switch(cType)
{
case "TextBox":
((TextBox)c).Enabled = false;
break;
case "DropDownList":
((DropDownList)c).Enabled = false;
break;
我的问题是页面里有datagrid,datagrid里面还有控件,想把datagrid里面的索引控件也Disabled
或者Enabled ?,如果有其他方法也可以
datagrid.ITEMS[0].Enabled = false;
这种方法好像不行哦

解决方案 »

  1.   

    用TextBox做例子
    TextBox TextBoxID=(TextBox)datagrid.Items.FindControl("TextBoxID");
    TextBoxID.Enabled = false;
      

  2.   

    你要做一个递归来遍历,给你几个我的函数,希望你不是直接拿去用而是看懂它:    /// <summary>
        /// 递归向下寻找控件
        /// </summary>
        /// <param name="control"></param>
        /// <param name="ID"></param>
        /// <returns></returns>
        static public Control FindControl ( Control control, string ID )
        {
          if ( control.ID == ID )
            return control;      foreach ( Control child in control.Controls )
          {
            Control resault;        if ( (resault = FindControl( child, ID )) != null )
              return resault;
          }
          return null;
        }    /// <summary>
        /// 找出指定类型的控件
        /// </summary>
        /// <param name="control"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        static public Control[] FindControls ( Control control, Type type )
        {
          return FindControls( control, type, false );
        }
        
        /// <summary>
        /// 找出指定类型的控件
        /// </summary>
        /// <param name="control"></param>
        /// <param name="type"></param>
        /// <param name="SubClass"></param>
        /// <returns></returns>
        static public Control[] FindControls ( Control control, Type type, bool SubClass )
        {
          ArrayList list = new ArrayList();      if ( ( control.GetType().IsSubclassOf( type ) && SubClass ) || ( control.GetType() == type ) )
            list.Add( control );      foreach ( Control child in control.Controls )
          {
            list.AddRange( FindControls( child, type, SubClass ) );
          }      return (Control[]) list.ToArray( typeof( Control ) );
        }
      

  3.   

    给一个参考 
    //控制页面编辑状态
    public void EnablePageMode(Control ctl,bool blnYes)
    {

    for (int j = 0;j < ctl.Controls.Count ;j++)
    { if(ctl.Controls[j].Controls.Count > 0)
    {

    EnablePageMode(ctl.Controls[j],blnYes);
    }
    else
    {
    string id = ctl.Controls[j].ID;
    object o = ctl.Controls[j];

    if (o is System.Web.UI.WebControls.DropDownList)
    {
    DropDownList ddl=(System.Web.UI.WebControls.DropDownList)o;

    ddl.Enabled =blnYes;
    } else if ( o is TextBox)
    {
    TextBox txt=(System.Web.UI.WebControls.TextBox)o;
    txt.Enabled  =blnYes;

    }
    else if(.......)
    }
    }
    }
      

  4.   

    在里面放一个DIV,把DATAGRID里的东西放到DIV里去,然后让DIV进行隐藏,试试!
      

  5.   

    to sfwxw0456(全职杀手) (我不是要隐藏,是要Disabled