1.利用递归遍历所有控件
1 //递归遍历所有的控件(TextBox)
2 public static void LoopingControls(Control myControl)
3 {
4 foreach(Control frmcontrols in myControl.Controls)
5 {
6 if(frmcontrols.GetType().ToString()=="System.Web.UI.WebControls.TextBox")
7 {
8 ((TextBox)frmcontrols).Enabled=false;
9 }
10 if(frmcontrols.HasControls())
11 {
12 LoopingControls(frmcontrols);
13 }
14 }
15 }
16
17 //示例调用
18 LoopingControls(Page);
2 public static void LoopingControls(Control myControl)
3 {
4 foreach(Control frmcontrols in myControl.Controls)
5 {
6 if(frmcontrols.GetType().ToString()=="System.Web.UI.WebControls.TextBox")
7 {
8 ((TextBox)frmcontrols).Enabled=false;
9 }
10 if(frmcontrols.HasControls())
11 {
12 LoopingControls(frmcontrols);
13 }
14 }
15 }
16
17 //示例调用
18 LoopingControls(Page);
2.控件数组的操作
1 //控件数组
2 <asp:textbox id="txtOpinion1" runat="server" Width="100%" BorderStyle="None" Height="60px"></asp:textbox>
3 <asp:textbox id="txtOpinion2" runat="server" Width="100%" BorderStyle="None" Height="60px"></asp:textbox>
4 <asp:textbox id="txtOpinion3" runat="server" Width="100%" BorderStyle="None" Height="60px"></asp:textbox>
5 <asp:textbox id="txtOpinion4" runat="server" Width="100%" BorderStyle="None" Height="60px"></asp:textbox>
6
7 //对特定的控件进行操作
8 int i=1;
9 TextBox t=(TextBox)this.FindControl("txtOpinion"+sLevNow);
10 t.Enabled =true;
2 <asp:textbox id="txtOpinion1" runat="server" Width="100%" BorderStyle="None" Height="60px"></asp:textbox>
3 <asp:textbox id="txtOpinion2" runat="server" Width="100%" BorderStyle="None" Height="60px"></asp:textbox>
4 <asp:textbox id="txtOpinion3" runat="server" Width="100%" BorderStyle="None" Height="60px"></asp:textbox>
5 <asp:textbox id="txtOpinion4" runat="server" Width="100%" BorderStyle="None" Height="60px"></asp:textbox>
6
7 //对特定的控件进行操作
8 int i=1;
9 TextBox t=(TextBox)this.FindControl("txtOpinion"+sLevNow);
10 t.Enabled =true;