vb.net radio button list check if selected

asp.net, vb.net

Solution

Use the `SelectedIndex` proprty to check if anything is selected and the `SelectedItem` property to get the selected item's text:

If rbIsRep.SelectedIndex > - 1 Then
    Dim selectedItemsText = "You selected: " & rbIsRep.SelectedItem.Text
End If

You can change the selection programmatically for example with the `SelectedValue` property.

rbIsRep.SelectedValue = "0"

or declaratively from aspx

<asp:RadioButtonList ID="rbIsRep" runat="server"  RepeatDirection="horizontal" >
    <asp:ListItem Value="1" >Yes</asp:ListItem>
    <asp:ListItem Selected="True" Value="0" >No</asp:ListItem>
</asp:RadioButtonList>

Problem

I have the following: ``` <asp:RadioButtonList ID="rbIsRep" runat="server" RepeatDirection="horizontal" > <asp:ListItem Value="1" >Yes</asp:ListItem> <asp:ListItem Value="0" >No</asp:ListItem> </asp:RadioButtonList> ``` how do I check if the radiobuttonlist has any selected items?

Original source