Unlike web programming, radiobutton needs to be group by a groupbox, panel etc. and that's what i'm confused at. I have two radiobutton that is 'yes' and 'no', what I want is to determine what object to declare in parameters used for the two to get its value.

My code

cmd.Parameters.Add("@yesno", SqlDbType.NVarchar).Value = ??

what object to use where?

you can test with code like :

bool yes = false;
yes = radioY.selected==true && radioN.selected == false ?true:false;

or be more specific by something like

if(radioY.selected == true && radioN.selected == false)
//your yes radio is selected
yes = true;
   if(radioN.selected == true && radioY.selected == false)
//your no radio is selected
 yes = false;



@mshauny: are you sure that's correct ?

@Angelic One: The property called Checked should do the job, like this:

bool yes = YesRadioButton.Checked ? true : false;

Hope this helps :)


I tried

string str = "";
            if (radioButton1.Checked)
                str = "Y";
            if (radioButton2.Checked)
                str = "N";
            cmd.Parameters.Add("@paperback", SqlDbType.NVarChar).Value = str;

This works. Thanks for the two of you.. =)

Oh sorry guys, i did not know the exact property name of it. its not selected its checked. Thanks to CloneXpect for that.

I should start using the IDE to avoid such errors, but at least you got the concept.

Edited 6 Years Ago by mshauny: n/a

This question has already been answered. Start a new discussion instead.