radio button - c# Geting values of multiple group of radiobuttons -



i've c# windows form application contains multiple groups , each group contains of radio buttons. want insert values of each group access database table. i’am trying return every function doing

private void get_gender(radiobutton genderbutton)         {             if (genderbutton.checked)             {                 return genderbutton.text;             }         }  private void get_age(radiobutton agebutton)         {             if (agebutton.checked)             {                 return agebutton.text;             }         } private void get_interest(radiobutton interestbutton)         {             if (interestbutton.checked)             {                 return interestbutton.text;             }         } 

then trying pick them functions like

string gender = get_gender(i don’t know put here); string age= get_age(i don’t know put here); string interestr = get_interest(i don’t know put here); 

and create connection..(this no problem)

oledbconnection con = new oledbconnection(); command cmd = new oledbcommand(“insert tbl (age, gender, interest) “+”values(@age, @gend, @int”, con);   

query not problem ,

 values of 3 groups. getting values (@age, @gend, @int”, con);  

getting me crazy… there simple way checked radiobutton code instead of checking every radio button in each group whether checked or not ? pls se image.. understand more. pls guys , thank in advance.

you pass in list of radio button objects, loop through them until first selected. main issue different objects, though grouped , can have 1 selected.

var radiobuttons = new list<radiobutton>(); radiobutton.add(form.rbgendermale); radiobutton.add(form.rbgenderfemale); 

then get_gender method can like

private void get_gender(list<radiobutton> genderbuttons) {     foreach (var genderbutton in genderbuttons)     {         if (genderbutton.checked)         {             return genderbutton.text;         }      }  } 

if using dynamic radio buttons or don't care of effects reflection have idea of adding new radio buttons form group without having change code behind take @ how checked radio button in groupbox?


Popular posts from this blog