asp.net控制元件全部清空、全部啟用、全部禁用方法
阿新 • • 發佈:2019-01-25
#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;
}
}