asp.net 遍历页面控件包含子控件,变为只读
遍历所有控件s
1 protected void approval()
2 {
3 foreach (Control control in this.Page.Controls)
4 {
5 SetReadOnly(control);
6 }
7 }
1 //将单个控件包含子集变为只读
2 protected void SetReadOnly(Control ctrl)
3 {
4 if (!ctrl.HasControls())
5 {
6 if (ctrl is TextBox)
7 {
8 TextBox tb = (TextBox)ctrl;
9 tb.Enabled = false;
10 }
11 if (ctrl is DropDownList)
12 {
13 DropDownList ddl = (DropDownList)ctrl;
14 ddl.Enabled = false;
15 }
16 if (ctrl is FileUpload)
17 {
18 FileUpload fu = (FileUpload)ctrl;
19 fu.Enabled = false;
20 }
21
22 }
23 else
24 {
25 int i = 0;
26 while (i < ctrl.Controls.Count)
27 {
28 SetReadOnly(ctrl.Controls[i]);
29 i++;
30 }
31 }
32 }