//获取所有dropdownlist类型的控件放到list中
List<System.Web.UI.Control> list2=GetControls(this.Controls, typeof(DropDownList));
//对page下的所有子控件的子控件进行循环遍历,获取dropdownlist类型控件
private List<System.Web.UI.Control> GetControls(System.Web.UI.ControlCollection ctrls, Type type)
{
List<System.Web.UI.Control> list = new List<System.Web.UI.Control>();
foreach (System.Web.UI.Control ctrl in ctrls)
{
if (ctrl.GetType() == type)
{
list.Add(ctrl);
}
if (ctrl.Controls.Count > 0)
{
foreach (Control con in GetControls(ctrl.Controls, type))
{
list.Add(con);
}
}
}
return list;
}