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 = ??

Recommended Answers

All 4 Replies

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;
}
else
 {
   if(radioN.selected == true && radioY.selected == false)
{
//your no radio is selected
 yes = false;
}
}

Goodluck

commented: nice +1

@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 :)

commented: thanks +1

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.

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.