Search code examples
asp.netvb.netradiobuttonlist

how to display selected value from radiobuttonlist


I tried

Dim theme = rblTheme.Items(rblTheme.SelectedIndex).Value

getting first value selected

Dim theme = rblTheme.SelectedItem.Value

getting first value selected

Dim theme = ""
        For i As Integer = 0 To rblTheme.Items.Count - 1

            If (rblTheme.Items(i).Selected) Then
                theme = rblTheme.Items(i).Value
            End If
        Next

Getting both value selected.

Need help !!


Solution

  •  Dim selectedItemVal as string
     selectedItemVal=rblTheme.SelectedValue;
    

    I guess you are reloading the RadioButton list in the page postback again (when you click on some button). So probably you should move that code If isPostBack property is false

     protected void Page_Load(object sender, EventArgs e)
     {
         if(!IsPostBack)
         {
            //Your code to load the Radio button list control
         }
     }
    

    Now you should be able to get the value on your button click event.