一般遍历可以采用两种方面:循环和递归,两者执行效果一样
下面以遍历TextBox为例说明:
一,循环遍历:
1
protected void Find()
2
{
3
HtmlForm from = (HtmlForm)this.FindControl("form1");
4
for (int i = 0; i < from.Controls.Count; i++)
5
{
6
if (from.Controls[i] is TextBox)
7
{
8
TextBox tb = from.Controls[i] as TextBox;
9
tb.Text = "";
10
}
11
}
12
}

2



3

4

5



6

7



8

9

10

11

12

二,递归遍历:
1
protected void Find(Control c)
2
{
3
if (c.Controls != null)
4
{
5
foreach (Control x in c.Controls)
6
{
7
if (x is System.Web.UI.WebControls.TextBox)
8
{
9
((System.Web.UI.WebControls.TextBox)x).Text = "";
10
}
11
Find(x);
12
}
13
}
14
}

2



3

4



5

6



7

8



9

10

11

12

13

14
