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.

Recommended Answers

All 3 Replies

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
            }


        }
commented: Was about to pose a similar question, until I found this! +4

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?

you should always go to the source to check for values

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.