selected in radio button list?

xJustin8x

Member
Joined
Mar 20, 2011
Messages
5
Programming Experience
Beginner
I have a radio button list that I am trying to do an if then statement for.

How can you make the radio button list statement so that if a user does not select any items at all they get an error such as label1.text = "please select an option"

Thanks!
 
Last edited by a moderator:
I have a radio button list that I am trying to do an if then statement for.

How can you make the radio button list statement so that if a user does not select any items at all they get an error such as label1.text = "please select an option"

Thanks!

VB.NET:
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim opt As String
		Select Case True
			Case RadioButton1.Checked
				opt = "One"
			Case RadioButton2.Checked
				opt = "Two"
			Case RadioButton3.Checked
				opt = "Three"
			Case Else
				opt = "Please make a selection"
		End Select
		Label1.Text = opt
	End Sub
 
How does it know which radio button list i am referring to though? I have a couple radio button lists...

Also, I am sorry I think I should have posted this in ASP.Net forum..
 
If you never bothered changing the default names of the controls, you can use the fullly-qualified name including the container, for example: GroupBox1.RadioButton1.Checked

But why would you use the same names for each container? Ideally, you should use unique descriptive names for each of your controls instead of the default names. Then only that name would need to be used without needing to refer to the container.

For example, if you have a group of controls for a color and another group for the size, you should rename the controls as radRed, radBlue, radGreen, radLarge, radMedium, radSmall. You would then use two separate Select Case blocks, one for each group.
 
Last edited:
Also, I am sorry I think I should have posted this in ASP.Net forum..
I think so too, and have moved the thread to ASP.NET section of forums.
In addition you can make it simpler to help you, for example why write "radio button list" when you can write "RadioButtonList"? "radio button list" in comparison almost sounds like you're listening to radio, fiddling with a button, while writing the grocery list.
RadioButtonList Properties (System.Web.UI.WebControls)
Scrolling through that and looking into SelectedIndex property makes me think the answer lies in this.
 
Back
Top