1,105,332 Community Members

getting the selected item from a radioButton group

Member Avatar
Twyce
Newbie Poster
1 post since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
Ryshad
Nearly a Posting Virtuoso
1,263 posts since Aug 2009
Reputation Points: 480 [?]
Q&As Helped to Solve: 247 [?]
Skill Endorsements: 14 [?]
 
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
            }


        }
Member Avatar
sknake
Senior Poster
3,957 posts since Feb 2009
Reputation Points: 1,620 [?]
Q&As Helped to Solve: 747 [?]
Skill Endorsements: 25 [?]
Featured
 
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?

Member Avatar
Ryshad
Nearly a Posting Virtuoso
1,263 posts since Aug 2009
Reputation Points: 480 [?]
Q&As Helped to Solve: 247 [?]
Skill Endorsements: 14 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article