一个aspx页面里所有的控件

for (int j = 0; j < this.Controls.Count; j++)       
          { 
foreach (object o in Page.Controls[j].Controls)  
{    
if (o is  DropDownList)  
{  
  DropDownList drop = (System.Web.UI.WebControls.DropDownList)o;   
if (drop.ID.Contains("C"))
{
BindCoro(drop);
}  

}   

void Emptcontro(Control cc)//清空页面所有的textbox文本
{
if (cc == null)
{
for (int j = 0; j < this.Controls.Count; j++)
{
foreach (Control o in Page.Controls[j].Controls)
{
Emptcontro(o);
if (o is TextBox)
{
TextBox txt = (System.Web.UI.WebControls.TextBox)o;
txt.Text = string.Empty;
}
}
}
}
else {
if (cc is TextBox)
{
TextBox txt = (System.Web.UI.WebControls.TextBox)cc;
txt.Text = string.Empty;
}
else
{
foreach (Control o in cc.Controls)
{
Emptcontro(o);
}
}
}
}

原文地址:https://www.cnblogs.com/lucoo/p/2658488.html