ASP.NET RadioButtonList Control
The Radio Button List control is used to present options for your user to
choose from but only allow them to select one option from the group. Think of
using a radiobuttonlist control when you want to get an either/ or answer from
your user based on a provided selection of options. You can either define the
available options using the .text property of each button in the list or you can
programmically present the options to a datasource that you define and then bind
the radio button control to the datasource.
You can then program a procedure (using Visual Basic or C#) to perform an action
based on the selection the user provided. If you have a small form like the one
below and want an immediate response once the user has made a selection then set
AutoPostBack = "true". But if you have the control on a form with many
other controls then you want to wait until the submit button has been clicked
before you preform the action to respond based on the answer the user provided.
When this is the case then you will look for the .checked
property to get the results.
RadioButtonList Control with AutoPostBack = "true"
The RadioBoxList control is used to group the questions. A user can only select
1 radio button per group.
Below is an example of when you might use a radio button control.
Below is the code to create the form above.
ASP.NET
<asp:RadioButtonList ID="radioSizes" runat="server"
RepeatDirection="Horizontal" AutoPostBack="True" >
<asp:ListItem>Small</asp:ListItem>
<asp:ListItem>Medium</asp:ListItem>
<asp:ListItem>Large</asp:ListItem>
<asp:ListItem>Extra-Large</asp:ListItem>
<asp:RadioButtonList>
<asp:Label ID="lblPrice" style="color:green;" runat="server" Text="Label" />
VB.NET
Protected Sub radioSizes_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles radioSizes.SelectedIndexChanged
Dim sizeSelected As String = radioSizes.SelectedValue
Dim showPrice As String = ""
Select Case sizeSelected
Case "Small"
showPrice = "$5.95"
Case "Medium"
showPrice = "$6.95"
Case "Large"
showPrice = "$7.9
Case "Extra-Large"
showPrice = "$8.95"
End Select
lblPrice.Text = showPrice
End Sub
You can hand type in all of the items or you can "bind" your control to a DataSource.
ASP.NET
Web Controls
Standard Controls
List Controls
Images & Links
Navigation