The RadioButtonList control is used to create a group of radio buttons.
RadioButtonList are used when we need to make multiple sets of choices available, but we want the user to select only one of them. If they click on a second selection after making a first, the first selection is removed.
RadioButtonList also supports data binding.
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem>c#</asp:ListItem>
<asp:ListItem>j#</asp:ListItem>
<asp:ListItem>vb</asp:ListItem>
<asp:ListItem>c++</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
</asp:RadioButtonList>

RadioButtonList event
The default event of the RadioButtonList is the SelectedIndexChanged
<asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"
Font-Bold="True" Font-Italic="True" Font-Names="Arial" ForeColor="Red"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem>c#</asp:ListItem>
<asp:ListItem>j#</asp:ListItem>
<asp:ListItem>vb</asp:ListItem>
<asp:ListItem>c++</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
</asp:RadioButtonList>
protected void RadioButtonList1_SelectedIndexChanged (object sender, EventArgs e)
{
Label1.Text = RadioButtonList1.SelectedItem.Text;
}

When you select any option then SelectedIndexChanged event will fire and it will show the selected value in Label.
We can change RadioButton appearance
<asp:RadioButtonList ID="RadioButtonList1" runat="server" Font-Bold="True"
Font-Italic="True" Font-Names="Arial" ForeColor="Red"
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
<asp:ListItem>c#</asp:ListItem>
<asp:ListItem>j#</asp:ListItem>
<asp:ListItem>vb</asp:ListItem>
<asp:ListItem>c++</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
</asp:RadioButtonList>

Leave Comment
2 Comments