yueyue, I have fallen in love with you for

2011-02-09, 01:18:25 PM

强大的功能实现类中的一些常用方法

Posted on 2011-09-02 16:02  张超的博客  阅读(168)  评论(0)    收藏  举报

//第一个方法是禁用和激活当前页面所指定类型控件的方法,代码如下:

View Code
 /// <summary>
/// 遍历页面上所有控件
/// </summary>
/// <param name="page">指定的Page</param>
/// <param name="flag">false-不可用,true-可用</param>

public void ControlReadOnly(System.Web.UI.Control page, bool flag)
{
int nPageControls = page.Controls.Count;
for (int i = 0; i < nPageControls; i++)
{
foreach (System.Web.UI.Control control in page.Controls[i].Controls)
{
if (control is TextBox)
(control
as TextBox).Enabled = flag;
if (control is DropDownList)
(control
as DropDownList).Enabled = flag;
}
}
}

 

//将文本框置空的方法:

View Code
/// <summary>
/// 将文本框置空
/// </summary>
public void ClearAll(System.Web.UI.Control page)
{
int nPageControls = page.Controls.Count;
for (int i = 0; i < nPageControls; i++)
{
foreach (System.Web.UI.Control control in page.Controls[i].Controls)
{
if (control is TextBox)
(control
as TextBox).Text = "";
if (control is Label)
(control
as Label).Text = "";
if (control is DropDownList)
(control
as DropDownList).TabIndex = 0;
}
}
}

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3