Looping thru a controls collection to get properties of that contr

J

JoeG

I'm very new to ASP.Net programing, so I hope I can explain what I want to do.
I used the following code to create anywhere from 1 to 16 radiobuttonlist in
a placeholder, each with two "listitems" added to each. What I want to do is
check to see what item the user picked for each of the radiobuttonlists.
For I=2 to FldCount step 2
If myreader.IsDbNull(i)=False then
Dim myRBList As RadioButtonList = New RadioButtonList()
myRBList.ID = "ID" & i
myrblist.repeatcolumns=2
myrblist.cellpadding=1
myrblist.cellspacing=2
myrblist.enableviewstate=True
myRBList.items.add(myreader.getstring(i))
myrblist.items.add(myreader.getstring(i + 1))
Placeholder1.Controls.Add(myRBList)
end if
next I
dim oControl as control
For Each oControl In Placeholder1.Controls
If TypeOf ocontrol Is radiobuttonlist Then
"Once here how do I get to the collection that contains the
items selected"
End If
Next

If anyone knows of any good websites/articles that can explain controls
collection or show how to iterate thru them, I would appreciate it.
 
W

Wilco Bauwer

1. I would use a databound control instead, such as a Repeater. In that
case you can do most of your stuff declaratively, and you don't have to
take control recreation into account (upon postbacks). So it's less
error prone too.
2. Upon a postback, you can check a radio button list's Selected*
property.


In case you don't want to go for 1., you have to take into account that
adding a control dynamically, means that the control is ONLY added to
the control hierachy for the CURRENT request. So upon a postback, its
NOT there anymore, and you have to RECREATE it. If you dont do this
properly, you'll have problems with events not being fired, etc.

HTH.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top