Search code examples
vb.netradio-buttoncheckedunchecked

How to check one radio button out of two in vb.net


Suppose I have 2 radio buttons r1 and r2, both the radio buttons ask for your gender, you can be a man or woman.

So what I want: if user checks r1 but then realizes that she is a woman, she then wants to check r2 so the control on r2 gets checked while r1 gets unchecked.

 <tr>
     <td>
         <asp:Label runat="server"  text="Chooose Your Category" ID="lblcategory"></asp:Label>
     </td>
     <td>
         <asp:RadioButton runat="server" Text="Male" ID="rbgold" />
     </td>
     <td>
         <asp:RadioButton runat="server" Text="Female" ID="rbsilver" /> 
     </td>
 </tr>

What should I do next so as I can choose only one?

Thanks in advance.


Solution

  • I got my answer by using an asp:RadioButtonList

    <tr>
        <td>
            <asp:Label runat="server"  text="Chooose Your Category" ID="lblcategory">
            </asp:Label>
        </td>
        <td class="style1">
            <asp:RadioButtonList ID="rbgold" runat="server" 
                        RepeatColumns="2"
                        Width="200px">
                <asp:ListItem Text="Silver class" value="1" ></asp:ListItem>
                <asp:ListItem Text="Gold class" value="2"></asp:ListItem>
            </asp:RadioButtonList>   
        </td>    
    </tr>