I am trying to get the seleted radioButton from a group of radio buttons.
The program is supposed to check on the database for controls that match the selected radiobuttons. The radiobuttons are named High,Medium,Low.
For example

If a person selects High, the program must go through the database and choose all the controls that are rated High and then must load them into a listBox.

My problem is that the code i am using does not see the selected items and does not load the listBox.
I am usig SQL server database and stored procedures to do this.

Any suggestions on how i can go about doing this will be appreciated.

7 Years
Discussion Span
Last Post by Geekitygeek

EDIT: re-read your post and realised you need to poulate the list when the radio is changed, revised code :)

Rather than checking each one for the check status, why not handle the controls check changed event to show list:

//in designer
this.rdoHigh.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
this.rdoMedium.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
this.rdoLow.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
//set the rdo Text to the desired value: High/Medium/Low
//then handle the check changed event to update list

       private void radioButton_CheckedChanged(object sender, EventArgs e)

            string selected = String.Empty;

            if (((CheckBox)sender).Checked)
                Selected = ((CheckBox)sender).Text;
            //execute query and populate list


Edited by Geekitygeek: n/a

Votes + Comments
Was about to pose a similar question, until I found this!

Ryshad: I don't agree with that approach, you should always go to the source to check for values. If not you leave an opportunity for the values to become desynched and it will load to a bug. It will probably work 99.9% of the time but that other 0.1 bothers me ;)

Twyce: Can you explain what you are trying to accomplish in more detail?

Edited by sknake: n/a


you should always go to the source to check for values

your right of course, i think my revised code covers that too right?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.