Looping thru a controls collection to get properties of that contr

Discussion in 'ASP .Net Web Controls' started by JoeG, Feb 15, 2005.

  1. JoeG

    JoeG Guest

    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.
    JoeG, Feb 15, 2005
    #1
    1. Advertising

  2. JoeG

    Wilco Bauwer Guest

    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.
    Wilco Bauwer, Feb 15, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TmV3YXNwcw==?=
    Replies:
    0
    Views:
    683
    =?Utf-8?B?TmV3YXNwcw==?=
    Jun 12, 2004
  2. Craig G
    Replies:
    5
    Views:
    541
    Craig G
    Feb 22, 2005
  3. Craig G

    Looping thru controls - part 2!!

    Craig G, Feb 22, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    361
    Craig G
    Feb 24, 2005
  4. Øyvind Isaksen
    Replies:
    1
    Views:
    949
    Øyvind Isaksen
    May 18, 2007
  5. tshad
    Replies:
    1
    Views:
    466
    bruce barker
    Sep 6, 2007
Loading...

Share This Page