Reputation: 75
Here is my sample code
for (int i = 0; i< sdtable1.rows.count ; i++) {
System.Web.UI.Control ctr = SDTable1.Rows[i].Cells[0].Controls[i];
StudentDetailsChecklist.Items.Add(ctr.ID);
}
SDTable is my Html table, I want to fetch the control names not Id.
If I use the above code it fetches the ID of the controls, I need to fetch the name of the control.
Thanks Rajeshkumar
Upvotes: 0
Views: 322
Reputation: 3839
It boils down to enumerating all the controls in the control hierarchy:
IEnumerable<Control> EnumerateControlsRecursive(Control parent)
{
foreach (Control child in parent.Controls)
{
yield return child;
foreach (Control descendant in EnumerateControlsRecursive(child))
yield return descendant;
}
}
You can use it like this:
foreach (Control c in EnumerateControlsRecursive(Page))
{
if(c is TextBox)
{
// do something useful
}
}
Upvotes: 1