这个问题在论坛上的提问比较频繁的,这里总结一下几种方法,希望对没用过的朋友有所帮助^_^。
高手就不用看了 ![]()
方法一:
1

#region
2
/**//// <summary>
3
/// 功能描述:遍历Asp.net窗体上所有的控件
4
/// 作者:Terrylee
5
/// 日期:2005年10月09日
6
/// </summary>
7
/// <param name="page">要设置的页面</param>
8
private void PrivilegeCheck(System.Web.UI.Control page)
9
{
10
for(int i=0;i<page.Controls.Count;i++)
11
{
12
foreach (System.Web.UI.Control control in page.Controls[i].Controls)
13
{
14
if(control is LinkButton)
15
{
16
if(true) //仅为了测试:)
17
{
18
((LinkButton)control).Enabled = false;
19
}
20
else
21
{
22
((LinkButton)control).Enabled = true;
23
}
24
}
25
else if(control is TextBox)
26
{
27
((TextBox)control).Text = "想要设置的内容";
28
}
29
else
30
{
31
//……
32
}//if
33
}//foreach
34
}//for
35
}
36
#endregion


#region2

/**//// <summary>3
/// 功能描述:遍历Asp.net窗体上所有的控件4
/// 作者:Terrylee5
/// 日期:2005年10月09日6
/// </summary>7
/// <param name="page">要设置的页面</param>8
private void PrivilegeCheck(System.Web.UI.Control page)9

{10
for(int i=0;i<page.Controls.Count;i++)11

{12
foreach (System.Web.UI.Control control in page.Controls[i].Controls)13

{14
if(control is LinkButton)15

{16
if(true) //仅为了测试:)17

{18
((LinkButton)control).Enabled = false;19
}20
else21

{22
((LinkButton)control).Enabled = true;23
}24
}25
else if(control is TextBox)26

{27
((TextBox)control).Text = "想要设置的内容";28
}29
else30

{31
//……32
}//if33
}//foreach34
}//for35
}36
#endregion稍后继续其他的:)