|
RadioButton
The RadioButton Web server control is similar to CheckBox but RadioButtons are displayed
as rounded instead of box. The class hierarchy for this control is as follows:
Object
Control
WebControl
CheckBox
Radiobutton
Radiobutton Event
The default event of the RadioButton is the CheckedChanged event
which looks like this in code:
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles RadioButton1.CheckedChanged
'Implementation Omitted
End Sub
|
Notable property of the RadioButton control is the GroupName property
which sets the radio button's group. The radio button will act in concert with the
other members of the group.
RadioButton Sample
Drag three radio button's, a textbox and a button on to the form. Select each
radio button and set the GroupName property for each to ABC. If you do not set the
GroupName property to a common name then each radio button will act differently and
when you make a selection all radio buttons will be rounded. In most cases, you want
your users to select only one option from a given list and to accompolish that you
need to set the GroupName property. The following code will display the text
of the radio button selected in a textbox when the button is clicked. Select each
radio button and set the Text as shown below and paste the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
If RadioButton1.Checked Then
TextBox1.Text = "You heard about us through " & " " & RadioButton1.Text
ElseIf RadioButton2.Checked Then
TextBox1.Text = "You heard about us through " & " " & RadioButton2.Text
ElseIf RadioButton3.Checked Then
TextBox1.Text = "You heard about us through " & " " & RadioButton3.Text
End If
End Sub
|
Live Code Demo
RadioButtons with no GroupName
When you make a selection all
radio buttons can be selected
RadioButton
Sample Demo
How did you hear about us?
|