根据指定的控件ID获取相应的控件
我用此方法主要用于找到GridView中的控件,核心代码如下:
1
public static Control getChildControl(Control ctl, string ControlID)
2
{
3
foreach (Control cctl in ctl.Controls)
4
{
5
if (cctl.ID == ControlID)
6
{
7
return cctl;
8
}
9
else
10
{
11
Control ctl2 = getChildControl(cctl, ControlID);
12
if (ctl2 != null)
13
{
14
return ctl2;
15
}
16
}
17
}
18
return null;
19
}
public static Control getChildControl(Control ctl, string ControlID)2
{3
foreach (Control cctl in ctl.Controls)4
{5
if (cctl.ID == ControlID)6
{7
return cctl;8
}9
else10
{11
Control ctl2 = getChildControl(cctl, ControlID);12
if (ctl2 != null)13
{14
return ctl2;15
}16
}17
}18
return null;19
}

浙公网安备 33010602011771号