0

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

7
  • You can do it easily using jquery Commented Sep 30, 2013 at 14:39
  • Please show us where you get stack rather than we try to guess. Commented Sep 30, 2013 at 14:49
  • I am just looking for the code friends. Commented Sep 30, 2013 at 14:57
  • 2
    @Rajeshkumar There are multiple ways to achieve it, but it all depends on how you create your html table. Please show us code how you create the html table. Commented Sep 30, 2013 at 15:02
  • Its a static table with static controls. I have to take the control name and pass it to the listbox. Its my scenario. Commented Sep 30, 2013 at 15:08

1 Answer 1

1

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
        }
    }

Source

Sign up to request clarification or add additional context in comments.

1 Comment

I just want to get the names of the controls inside the html table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.