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
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
Hi Kalyani
u should set Mr,Mrs,MIss one group and another one group
any doubt pl ask
Mar 5 '08 #2

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.          }
like that create another same group for residential and commerical radio buttons and write code as shown above..
Apr 7 '09 #3
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
  2. private GroupBox radioGroup;
  3. private RadioButton mrRadio;
  4. private RadioButton missRadio;
  5. private RadioButton mrsRadio;
  7. //The following method initializes the RadioButtons in a the GroupBox:
  8. public void InitializeRadioButtons()
  9. {
  10.     this.radioGroup = new System.Windows.Forms.GroupBox();
  12.     this.mrRadio = new System.Windows.Forms.RadioButton();
  13.     this.missRadio = new System.Windows.Forms.RadioButton();
  14.     this.mrsRadio = new System.Windows.Forms.RadioButton();
  16.     this.radioGroup.Controls.Add(this.mrRadio);
  17.     this.radioGroup.Controls.Add(this.missRadio);
  18.     this.radioGroup.Controls.Add(this.mrsRadio);
  21.     this.radioGroup.Location = new System.Drawing.Point(80, 75);
  22.     this.radioGroup.Height = 150;
  23.     this.radioGroup.Text = "Titles";
  25.     this.mrRadio.Text = "Mr";
  26.     this.mrRadio.Location = New Point(5, 15);
  28.     this.missRadio.Text = "Miss";
  29.     this.missRadio.Location = New Point(5, 35);
  31.     this.mrsRadio.Text = "Mrs";
  32.     this.mrsRadio.Location = New Point(5, 55);
  34. //Selecting "Mrs"
  35.     this.mrsRadio.Checked = true;
  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

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...
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,...
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"...
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...
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...
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...
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...
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...
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...
by: vinodkus | last post by:
dear sir/madam Please tell me how to refresh page using using code behind Thanks in advance
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...
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...
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...
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...
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...
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...
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...
by: lllomh | last post by:
How does React native implement an English player?
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.