Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through Page Controls

Status
Not open for further replies.

NWChowd

Programmer
May 26, 2002
84
US
Does anyone know how to loop through the Page.Controls collection on a web page in order to find all instances of a RadioButtonList?? For example,

foreach (RadioButtonList rb in Page.Controls){

}

only this statement doesn't work.

This exercise was much simpler in classic ASP, but I haven't quite figured it out in ASP.NET.



Thanks,
DMill ======================================
"I wish that I may never think the smiles of the great and powerful a sufficient inducement to turn aside from the straight path of honesty and the convictions of my own mind."
-David Ricardo, classical economist
======================================
 
It will surely work this way:

RadioButtonList rb;

foreach(Control ctrl in Page.Controls)
{
if(ctrl.GetType() != "RadioButtonList")
continue;

rb = (RadioButtonList) ctrl;
...
}

if you don't mind going through all the controls all the time...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top