1.11M Members

getting the selected item from a radioButton group

 
0
 

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.

 
1
 

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
            }


        }
 
1
 

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?

 
0
 

you should always go to the source to check for values

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

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article