try this..
while (dr.Read())
{
i = i + 1;
Panel p = new Panel();
p.Name="panel" + i.ToString();
parentControl.Controls.Add(p);
}
now to get the panels
foreach(Control c in parentControl.Controls)
{
if(c.GetType().Equals(typeof(Panel))
{
Panel temp = (Panel)c;
if(temp!=null && temp.Name=="panel3")
MessageBox.Show("Panel Found");
}
}
and if you dont want to loop the Controls of parentControl...
you can just access the particular panel by
Panel temp = (Panel)parentControl.Controls["panel3"];
if(temp!=null)
MessageBox.Show("Panel Found);
you can also get the Panel Collection of the 'parentControl' by using this statement..
var panelCollection = from Control c in parentControl.Controls where c.GetType().Equals(typeof(Panel)) select c;
foreach(Panel p in panelCollection)
{
}
hope this helps you..
take care