468,550 Members | 1,706 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,550 developers. It's quick & easy.

select radio buttom from given 3 radio buttons using c# code behind

can anybody help me out with my problem.
in my submit form i have three radio buttons with the title "Mr,Mrs,Miss".
how to select one radio button from the above three by using c# code behind.
also i have another two radio buttons titled "residential and commercial",
how to choose one radio button from the above two using C# code

with regards
kalyani
Mar 5 '08 #1
3 25081
can anybody help me out with my problem.
in my submit form i have three radio buttons with the title "Mr,Mrs,Miss".
how to select one radio button from the above three by using c# code behind.
also i have another two radio buttons titled "residential and commercial",
how to choose one radio button from the above two using C# code

with regards
kalyani
Hi Kalyani
u should set Mr,Mrs,MIss one group and another one group
any doubt pl ask
Regards
Venkatesan.M
Mar 5 '08 #2
hi

consider mr ,mrs ,miss as one group ,write one common group name for these three radio buttons.
Expand|Select|Wrap|Line Numbers
  1.  {
  2.            if( radiobutton1.checked)
  3.            { ....}
  4.            if( radiobutton2.checked)
  5.            {....}
  6.            if(radiobutton3.checked)
  7.            {...}
  8.          }
  9.  
like that create another same group for residential and commerical radio buttons and write code as shown above..
Apr 7 '09 #3
Frinavale
9,735 Expert Mod 8TB
If this is a web application I would recommend you take a look at the RadioButtonList Class. You access the radio button you want to select by through the RadioButton's Items property.

For example, if you had the following RadioButtonList declared in your ASPX code:
Expand|Select|Wrap|Line Numbers
  1. <asp:RadioButtonList ID="titles" runat="server">
  2.         <asp:ListItem id="mr" Text="Mr" Value="Mr"></asp:ListItem>
  3.         <asp:ListItem id="miss" Text="Miss" Value="Miss"></asp:ListItem>
  4.         <asp:ListItem id="mrs" Text="Mrs" Value="Mrs"></asp:ListItem>
  5. </asp:RadioButtonList>
You would select "Mrs" using C# like this:
Expand|Select|Wrap|Line Numbers
  1. titles.Items[2].Selected = true;

If you are developing a desktop application and you want the user to be able to select one value from a group of RadioButtons, then you need group the RadioButtons together in a GroupBox or Panel. Once they are grouped you use the Checked property to set the RadioButton that you want selected.

For example:

Expand|Select|Wrap|Line Numbers
  1.  
  2. private GroupBox radioGroup;
  3. private RadioButton mrRadio;
  4. private RadioButton missRadio;
  5. private RadioButton mrsRadio;
  6.  
  7. //The following method initializes the RadioButtons in a the GroupBox:
  8. public void InitializeRadioButtons()
  9. {
  10.     this.radioGroup = new System.Windows.Forms.GroupBox();
  11.  
  12.     this.mrRadio = new System.Windows.Forms.RadioButton();
  13.     this.missRadio = new System.Windows.Forms.RadioButton();
  14.     this.mrsRadio = new System.Windows.Forms.RadioButton();
  15.  
  16.     this.radioGroup.Controls.Add(this.mrRadio);
  17.     this.radioGroup.Controls.Add(this.missRadio);
  18.     this.radioGroup.Controls.Add(this.mrsRadio);
  19.  
  20.  
  21.     this.radioGroup.Location = new System.Drawing.Point(80, 75);
  22.     this.radioGroup.Height = 150;
  23.     this.radioGroup.Text = "Titles";
  24.  
  25.     this.mrRadio.Text = "Mr";
  26.     this.mrRadio.Location = New Point(5, 15);
  27.  
  28.     this.missRadio.Text = "Miss";
  29.     this.missRadio.Location = New Point(5, 35);
  30.  
  31.     this.mrsRadio.Text = "Mrs";
  32.     this.mrsRadio.Location = New Point(5, 55);
  33.  
  34. //Selecting "Mrs"
  35.     this.mrsRadio.Checked = true;
  36.  
  37.     this.ClientSize = new System.Drawing.Size(292, 266);
  38.     this.Controls.Add(this.radioGroup);
  39. }
Apr 7 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Ken Tucker | last post: by
reply views Thread by Shane O. Pinnell | last post: by
reply views Thread by khawar | last post: by
5 posts views Thread by Andrei Pociu | last post: by
5 posts views Thread by Matt | last post: by
9 posts views Thread by antonyliu2002 | last post: by
reply views Thread by vinodkus | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.