Link to home
Start Free TrialLog in
Avatar of mgmhicks
mgmhicks

asked on

How to iterate through radiobuttonlist

I have about 5 radiobuttonlist on a webpage.  I just want to make sure that something is selected.  They all default to no selection.  Here is the code, but I cant seem to get to where I tell if that perticular radiobutton has a selection or not.

Dim C As Control
        Dim frm As Control
        frm = FindControl("form1")
        For Each C In frm.Controls
            If TypeOf C Is RadioButtonList Then
                Dim myID As RadioButtonList
                myID = C.ClientID.ToString
                If myID.selecteditem = Nothing Then
                    VerifyAnswers = False
                End If
            Else
            End If

        Next

This isnt getting me what I need
Avatar of jppinto
jppinto
Flag of Portugal image

       Dim C As Control
        Dim frm As Control
        frm = FindControl("form1")
        For Each C In frm.Controls
            If TypeOf C Is RadioButtonList Then
                If C.Selecteditem = Nothing Then
                    VerifyAnswers = False
                End If
            End If
      Next
Avatar of mgmhicks
mgmhicks

ASKER

using vb and it comes back with c.selecteditem is not a member of system.web.ui.control
ASKER CERTIFIED SOLUTION
Avatar of jppinto
jppinto
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here is the final solution.  Split points because I needed both to solve the issue.  Here is the final code the key was the myControl = CType(c, RadioButtonList).  thanks

Private Function iterateControls(ByVal control As Control) As Boolean
        Dim myControl As New RadioButtonList
        For Each c As Control In control.Controls
            If TypeOf c Is RadioButtonList Then
                myControl = CType(c, RadioButtonList)
                If myControl.SelectedItem Is Nothing Then
                    iterateControls = False
                    Exit Function
                End If
            End If
        Next
        iterateControls = True
    End Function

Also instead of iteratecontrols(me) I had to use the form name.  iteratecontrols("Form1")