• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1023
  • Last Modified:

make radio button list dynamic

I have a radio button which has lists of country and state and city.  I like to change to a button to country and state in one condition and then change to country and state and city in other condition.  How to do this?  Thahks.
0
ewang1205
Asked:
ewang1205
  • 3
  • 2
1 Solution
 
mcgantsCommented:
You can make the radio button automatically post back to the server by selecting the control and making AutoPostBack = True

You can then add an event handler to the radio button as follows:
  Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

  End Sub

or to a list:
  Private Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged

  End Sub

Depending on which button is clicked, you can then update other radio buttons

Hope this helps,
mcg
0
 
ewang1205Author Commented:
I only have one radio button.  But, I like the list of the radio button to change dynamically. Thanks.
0
 
mcgantsCommented:
Sorry but I don't understand what you mean when you say 'the list of the radio button' - list isn't a command or feature of radio button,
Max
0
 
ewang1205Author Commented:
What I mean is the listitems of one list.  For example, a list has two items:  Country and City.  How to dynamically change the list to three items:  Country, State and City?  Thanks.
0
 
mcgantsCommented:
No worries, all you need to do is make sure the radio button has the AutoPostBack property set to true, then add the following code (changing the control names where necessary):

  Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
    If RadioButton1.Checked = True Then
      ListBox1.Items.Add("State")
    End If
  End Sub

When the user clicks the radio button, the list item will be added. As a side thought, if you want users to be able to add and remove from the list, use a Checkbox instead of a Radiobutton and use the following code:

  Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
    If CheckBox1.Checked = True Then
      ListBox1.Items.Add("State")
    Else
      ListBox1.Items.Remove("State")
    End If
  End Sub

Then, if the user selects the value in error, they can undo their mistake.

Hope this helps,
mcg
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now