RadioButton Control in ASP.Net



In previous asp.net server control post we had discussed about MultiView Control and ListBox Control and FileUpload Control and Adrotator Control and CheckBox Control and DropDownList Control and TextBox Control.

ASP.Net RadioButton Control

Radiobutton is a asp.net web server control. Radiobutton is used to allow user to select a single radiobutton from group of radiobutton. In a asp.net generally we use more than one radiobutton and select only one radiobutton at a time from all the radiobutton control. on other hand in checkbox control we can check and uncheck multiple check box at a time.

RadioButton Syntax :

<asp:RadioButton ID=RadioButton1 runat=server />

RadioButton Control ASP.Net Example

Now take an asp.net radiobutton example to understand more about radiobutton control.

How to use RadioButton control in asp.net c#.
How to use RadioButton control in asp.net c#.
Here are some important properties of radiobutton control in asp.net.
Checked = true/false, Indicate the radiobutton control is checked or unchecked.
GroupName =  GroupName property used to make a group of radiobutton. If we assign same value to more than one radiobutton then we can select only one radiobutton from that group of radiobutton.
How to use RadioButton control in asp.net c#.
How to use RadioButton control in asp.net c#.

HTML Design code for asp.net web forms:

<body>
    <form id="form1" runat="server">
    <div>
    
        <table align="center" class="style1" style="border: thin solid #008080">
            <tr>
                <td class="style2" 
                    style="text-align: center; border-bottom-style: solid; border-bottom-width: thin; border-bottom-color: #008080;">
                    RadioButton Control in ASP.Net</td>
            </tr>
            <tr>
                <td style="text-align: center">
&nbsp;
                    &nbsp;
                    </td>
            </tr>
            <tr>
                <td style="text-align: center">
                    <asp:RadioButton ID="radiored" runat="server" Text="RED" GroupName="my" />
&nbsp;
                    <asp:RadioButton ID="radioblue" runat="server" Text="BLUE" GroupName="my" />
&nbsp;
                    <asp:RadioButton ID="radiogreen" runat="server" Text="GREEN" GroupName="my" 
                        oncheckedchanged="radiogreen_CheckedChanged" />
                </td>
            </tr>
            <tr>
                <td style="text-align: center">
                    <asp:Button ID="Button1" runat="server" Height="26px" onclick="Button1_Click" 
                        style="font-weight: 700" Text="Select" />
                </td>
            </tr>
            <tr>
                <td style="text-align: center">
                    <asp:Label ID="Label1" runat="server"></asp:Label>
                </td>
            </tr>
            </table>
    
    </div>
    </form>
</body>
How to use RadioButton control in asp.net c#.
How to use RadioButton control in asp.net c#.

RadioButton Example C# Code :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default8 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (radiored.Checked == true)
        {
            Label1.Text = "You Selected Red";
        }
        else if (radioblue.Checked == true)
        {
            Label1.Text = "You Selected Blue";
        }
        else
        {
            Label1.Text = "You Selected Green";
        }
    }
}
How to use RadioButton control in asp.net c#.
How to use RadioButton control in asp.net c#.

Related ASP.Net Topics :

DropDownList Control
ListBox control in ASP.Net C#


Subscribe us

If you liked this asp.net post, then please subscribe to our YouTube Channel for more asp.net video tutorials.

We hope that this asp.net tutorial helped you to understand about RadioButton control.


Next, asp.net tutorial we will understand about TextBox Control.


Leave a Reply

Your email address will not be published. Required fields are marked *