asp.net控件全部清空、全部启用、全部禁用方法

 #region//控件类
    public class PubliClass
    {
        /// <summary>
        /// 清空控件内容
        /// </summary>
        public static void delContent(Control control)
        {
            foreach (Control ct in control.Controls)
            {
                Type tp = ct.GetType();
                if (tp.Name == "TextEdit")
                {
                    ((TextEdit)ct).EditValue = null;
                }
                else if (tp.Name == "LookUpEdit")
                {
                    ((LookUpEdit)ct).EditValue = null;
                    ((LookUpEdit)ct).ClosePopup();
                }
                else if (tp.Name == "CheckEdit")
                {
                    ((CheckEdit)ct).Checked = false;
                }
                //else if (tp.Name == "TextBox")
                //{
                //    ((TextBox)ct).Text = null;
                //}
                else if (tp.Name == "SpinEdit")
                {
                    ((SpinEdit)ct).Value = decimal.Zero;
                }
                else if (tp.Name == "MemoEdit")
                {
                    ((MemoEdit)ct).Text = null;
                }
                else if (tp.Name == "DateEdit")
                {
                    ((DateEdit)ct).EditValue = null;
                }
                else if (tp.Name == "ListBoxControl")
                {
                    ((ListBoxControl)ct).SelectedItem = null;
                }
                else if (tp.Name == "RadioGroup")
                {
                    ((RadioGroup)ct).SelectedIndex = int.MinValue;
                }
            }
        }
        /// <summary>
        /// 控件可用
        /// </summary>
        public static void EditableIS(Control control)
        {
            foreach (Control ct in control.Controls)
            {
                Type tp = ct.GetType();
                if (tp.Name == "TextEdit")
                {
                    ((TextEdit)ct).Enabled = true;
                }
                else if (tp.Name == "LookUpEdit")
                {
                    ((LookUpEdit)ct).Enabled = true;
                }
                else if (tp.Name == "CheckEdit")
                {
                    ((CheckEdit)ct).Enabled = true;
                }
                //else if (tp.Name == "TextBox")
                //{
                //    ((TextBox)ct).Enabled = true;
                //}
                else if (tp.Name == "SimpleButton")
                {
                    ((SimpleButton)ct).Enabled = true;
                }
                else if (tp.Name == "ListBoxControl")
                {
                    ((ListBoxControl)ct).Enabled = true;
                }
                else if (tp.Name == "DateEdit")
                {
                    ((DateEdit)ct).Enabled = true;
                }
                else if (tp.Name == "RadioGroup")
                {
                    ((RadioGroup)ct).Enabled = true;
                }
                else if (tp.Name == "MemoEdit")
                {
                    ((MemoEdit)ct).Enabled = true;
                }
            }
        }

        /// <summary>
        /// 控件不可用
        /// </summary>
        public static void EditableNO(Control control)
        {
            foreach (Control ct in control.Controls)
            {

                Type tp = ct.GetType();
                if (tp.Name == "TextEdit")
                {
                    ((TextEdit)ct).Enabled = false;
                }
                else if (tp.Name == "LookUpEdit")
                {
                    ((LookUpEdit)ct).Enabled = false;
                }
                else if (tp.Name == "CheckEdit")
                {
                    ((CheckEdit)ct).Enabled = false;
                }
                //else if (tp.Name == "TextBox")
                //{
                //    ((TextBox)ct).Enabled = false;
                //}
                else if (tp.Name == "SimpleButton")
                {
                    ((SimpleButton)ct).Enabled = false;
                }
                else if (tp.Name == "ListBoxControl")
                {
                    ((ListBoxControl)ct).Enabled = false;
                }
                else if (tp.Name == "DateEdit")
                {
                    ((DateEdit)ct).Enabled = false;
                }
                else if (tp.Name == "RadioGroup")
                {
                    ((RadioGroup)ct).Enabled = false;
                }
                else if (tp.Name == "MemoEdit")
                {
                    ((MemoEdit)ct).Enabled = false;
                }
            }
        }
    } 
    #endregion
foreach(Control   c   in   this.Controls) 
{ 
          if(c.Enable==true) 
          { 
                c.Enable=false; 
          } 
}



 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值