您的位置:首页 > 编程语言 > ASP

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

2012-01-31 14:47 459 查看
#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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: