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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kalyanibal
    New Member
    • Mar 2008
    • 1

    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,Mis s".
    how to select one radio button from the above three by using c# code behind.
    also i have another two radio buttons titled "residentia l and commercial",
    how to choose one radio button from the above two using C# code

    with regards
    kalyani
  • mvenkatesan
    New Member
    • May 2007
    • 39

    #2
    Originally posted by kalyanibal
    can anybody help me out with my problem.
    in my submit form i have three radio buttons with the title "Mr,Mrs,Mis s".
    how to select one radio button from the above three by using c# code behind.
    also i have another two radio buttons titled "residentia l 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

    Comment

    • sunny4063
      New Member
      • Apr 2009
      • 2

      #3
      code for radio buttons

      hi

      consider mr ,mrs ,miss as one group ,write one common group name for these three radio buttons.
      Code:
       {
                 if( radiobutton1.checked)
                 { ....}
                 if( radiobutton2.checked)
                 {....}
                 if(radiobutton3.checked)
                 {...}
               }
      like that create another same group for residential and commerical radio buttons and write code as shown above..

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        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:
        Code:
        <asp:RadioButtonList ID="titles" runat="server">
                <asp:ListItem id="mr" Text="Mr" Value="Mr"></asp:ListItem>
                <asp:ListItem id="miss" Text="Miss" Value="Miss"></asp:ListItem>
                <asp:ListItem id="mrs" Text="Mrs" Value="Mrs"></asp:ListItem>
        </asp:RadioButtonList>
        You would select "Mrs" using C# like this:
        Code:
        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:

        Code:
         
        private GroupBox radioGroup;
        private RadioButton mrRadio;
        private RadioButton missRadio;
        private RadioButton mrsRadio;
        
        //The following method initializes the RadioButtons in a the GroupBox:
        public void InitializeRadioButtons()
        {
            this.radioGroup = new System.Windows.Forms.GroupBox();
        
            this.mrRadio = new System.Windows.Forms.RadioButton();
            this.missRadio = new System.Windows.Forms.RadioButton();
            this.mrsRadio = new System.Windows.Forms.RadioButton();
        
            this.radioGroup.Controls.Add(this.mrRadio);
            this.radioGroup.Controls.Add(this.missRadio);
            this.radioGroup.Controls.Add(this.mrsRadio);
        
        
            this.radioGroup.Location = new System.Drawing.Point(80, 75);
            this.radioGroup.Height = 150;
            this.radioGroup.Text = "Titles";
            
            this.mrRadio.Text = "Mr";
            this.mrRadio.Location = New Point(5, 15);
        
            this.missRadio.Text = "Miss";
            this.missRadio.Location = New Point(5, 35);
        
            this.mrsRadio.Text = "Mrs";
            this.mrsRadio.Location = New Point(5, 55);
        
        //Selecting "Mrs"
            this.mrsRadio.Checked = true;
           
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.radioGroup);
        }

        Comment

        Working...