472,799 Members | 1,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,799 software developers and data experts.

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 26166
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

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

Similar topics

2
by: Ken Tucker | last post by:
I've read about this issue in many articles across the net... But haven't found a solution. I see all kinds of custom code to perform sorting with datagrids, but my example is so simple, I must...
0
by: Shane O. Pinnell | last post by:
Does anyone know of a resource for information on how to create a working databound DDL in a datagrid using code behind? I have found a plethora of resources for doing this without code-behind,...
0
by: khawar | last post by:
radio buttons give error messages when programming using code-behind If you guys can help you will save my life help help help. following is the a.aspx file: <%@ Page Inherits="MyCodeBehind"...
4
by: Marcel Balcarek | last post by:
I want to create a button using code-behind that only executes javascript, and does not post back to the server. How can I do this - my ImageButton insists on posting back to the server. Thank...
5
by: Andrei Pociu | last post by:
I have a major doubt about outputting text in ASP .NET when using code behind. I know most of the output you gain from a code behind file (.aspx.cs) is outputted to the Webform (.aspx) using...
6
by: Support | last post by:
Hello: USing the code behind model, i do not understand how to do a conditinal space in the aspx page. For example: I have two tables, under condition 1 I want table 1 to show and under condition...
5
by: Matt | last post by:
Hava aspx file ButtonTest.aspx, wiht below page directive <%@ Page language="c#" Codebehind="ButtonTest.cs" AutoEventWireup="false" Inherits="Actions.ButtonTest"%> I like to access to...
0
by: TCook | last post by:
Hey All, I'm trapping a 'submit' button's 'Click' event in a VB.Net code behind class in order to loop through a 'Select' controls 'option' list as follows: For Each ThisItem In...
9
by: antonyliu2002 | last post by:
I have a C# class GeneralUtilities.cs , which many of my aspx.cs files will refer to. So, I've put it under the App_Code folder and compiled it to library using csc /target: library from the DOS...
0
by: vinodkus | last post by:
dear sir/madam Please tell me how to refresh page using using code behind Thanks in advance
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.