Find control recursive in Asp.Net
2009-Жов-22, Четвер 13:37
public static Control FindControlRecursive(Control rootControl, string controlId)
{
Control foundControl;
if (rootControl.ID == controlId) return rootControl;
foreach (Control c in rootControl.Controls)
{
foundControl = FindControlRecursive(c, controlId);
if (foundControl != null) return foundControl;
}
return null;
}
public static T FindControlRecursive(Control rootControl, string controlId) where T : Control
{
Control ctrl = FindControlRecursive(rootControl, controlId);
return ctrl as T;
}