void DisplayAllControls(Control topctrl){
foreach(Control ctrl in topctrl.Controls){
if(ctrl.GetType().ToString()=="Label")
{
     ........
}
if(ctrl.HasControls())
    DisplayAllControls(ctrl);
}
}

解决方案 »

  1.   

    假设有一个panel crol控件,里面包这很多label控件
    private void InitData(Control crol)
    foreach(Control child in crol.Controls)
    {
        if(child.Controls.Count>0)
       {    InitData(child);
       }else
    {if(!(child is LiteralControl))
      {
         if(child is Lable)
         {
          ..........
          }
      }
    }
    }
      

  2.   

    foreach(Control ctr in this.Panel1.Controls)
    {

    if(ctr.GetType().ToString()=="System.Web.UI.WebControls.Label")
    {
      Response.Write("ID:"+ctr.ID+" TEXT:"+((Label)ctr).Text+"<br>");
    }}