ASP.NET RadioButton Control

Radio button control:

Asp.net Radiobutton control is used when you want to select one option from a set of given alternatives from web page.Radio button lets you make a group of radio buttons with other radio button.
If you set it's Group Name property same for multiple radio then all buttons associated with single group. Then within a group you can only select one button at a time.The html language also define Radiobutton in html page.

How to define RadioButton in asp.net



<asp:RadioButton ID="RadioButton1" runat="server"  AutoPostBack="true" Text="Button1" TextAlign="Left" ToolTip="select"/>

Radiobutton Group work as like RadioButtonList control. There are many properties that  help you to design radio button. 

Radio Button Class:

Asp.net RadioButton
Asp.net Radio Button

Radiobutton with RequiredFieldValidator


<asp:RadioButton ID="RadioButton1" runat="server"  AutoPostBack="true" Text="Button1" TextAlign="Left" ToolTip="select"/>
                                   <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
           ControlToValidate="RadioButtonList1" ErrorMessage="RequiredFieldValidator">
       </asp:RequiredFieldValidator>

 

Radio Button Properties:


  • AutoPostBack: Referee page on select.
  • Checked: Give a Boolean value true or false.
  • Id: Use for Access to control.
  • GroupName: For use Association.
  • Runat: define control execute at server end.
  • Text: define what you see in button text.

Much more like back color, border color, border style, font names, font bold, font italic, fore color (text color) and many more property.

How to use RadioButton control in asp.net:


For using here we give a Example.

                            <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="index" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>ASP.net How to use Radiobutton list control</title>   
</head>
<body>
    <form id="form1" runat="server">
     <div>       
        <fieldset>
            <h3>How to use Radiobutton list control</h3>
            <div>


            <asp:RadioButtonList ID="rbtLstRating" runat="server"
                RepeatDirection="Horizontal" RepeatLayout="Table">
                <asp:ListItem Text="Excellent" Value="Excellent"></asp:ListItem>
                <asp:ListItem Text="Very Good" Value="Very Good"></asp:ListItem>
                <asp:ListItem Text="Good" Value="Good"></asp:ListItem>
                <asp:ListItem Text="Fair" Value="Fair"></asp:ListItem>
                <asp:ListItem Text="Bad" Value="Bad"></asp:ListItem>
            </asp:RadioButtonList>           
            </div>
            <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
        </fieldset>       
         <fieldset>
            <h3>Selected Rating:</h3>
            <div>
                <asp:Label ID="lblSeletedRating" runat="server"></asp:Label>
            </div>
        </fieldset>       
    </div>
    </form>
</body>
</html>

How to radio button in asp.net 3.5 :


Taking Radio button on version of 3.5 of Asp.net.


                            <%@ Page Language="C#" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1-transitional.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head id="Head1" runat="server"> 
        <title>RadioButton example: how to use RadioButton control in asp.net</title> 
    </head>       
    <body> 
        <form id="form1" runat="server">
 <div>   <asp:RadioButton ID="RadioBtn1" runat="server" Text="button1" GroupName="Software" AutoPostBack="true”/>    <asp:RadioButton ID="RadioBtn2" runat="server" Text="button2" GroupName="Software" AutoPostBack="true " />  </div> 
        </form> 
    </body> 
</html> 
                            <br />
                            <table style="width: 50%">
                                <tr>
                                    <td align="center" colspan="2">
                                        <strong>Tokens List</strong>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" style="width: 50%">
                                        Year :
                                    </td>
                                    <td align="left" style="width: 50%">
                                        <asp:DropDownList ID="ddlYear" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlYear_SelectedIndexChanged" CssClass="input">
                                            <asp:ListItem Value="0">select</asp:ListItem>
                                            <asp:ListItem>2012</asp:ListItem>
                                            <asp:ListItem>2013</asp:ListItem>
                                            <asp:ListItem>2014</asp:ListItem>
                                            <asp:ListItem>2015</asp:ListItem>
                                            <asp:ListItem>2016</asp:ListItem>
                                            <asp:ListItem>2017</asp:ListItem>
                                            <asp:ListItem>2018</asp:ListItem>
                                            <asp:ListItem>2019</asp:ListItem>
                                            <asp:ListItem>2020</asp:ListItem>
                                            <asp:ListItem>2021</asp:ListItem>
                                        </asp:DropDownList>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right" style="width: 50%">
                                        Month :
                                    </td>
                                    <td align="left" style="width: 50%">
                                        <asp:DropDownList ID="ddlMonth" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlMonth_SelectedIndexChanged" CssClass="input">
                                            <asp:ListItem Value="0">Select</asp:ListItem>
                                            <asp:ListItem Value="1">January</asp:ListItem>
                                            <asp:ListItem Value="2">February</asp:ListItem>
                                            <asp:ListItem Value="3">March</asp:ListItem>
                                            <asp:ListItem Value="4">April</asp:ListItem>
                                            <asp:ListItem Value="5">May</asp:ListItem>
                                            <asp:ListItem Value="6">June</asp:ListItem>
                                            <asp:ListItem Value="7">July</asp:ListItem>
                                            <asp:ListItem Value="8">August</asp:ListItem>
                                            <asp:ListItem Value="9">September</asp:ListItem>
                                            <asp:ListItem Value="10">October</asp:ListItem>
                                            <asp:ListItem Value="11">November</asp:ListItem>
                                            <asp:ListItem Value="12">December</asp:ListItem>
                                        </asp:DropDownList>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        Date Wise :
                                    </td>
                                    <td align="left">
                                        <asp:TextBox ID="txtdate" runat="server" AutoPostBack="True" OnTextChanged="txtdate_TextChanged" CssClass="input"></asp:TextBox>
                                        <cc1:CalendarExtender ID="txtdate_CalendarExtender" runat="server" Format="dd-MMM-yyyy"
                                            Enabled="True" TargetControlID="txtdate" PopupButtonID="Image1">
                                        </cc1:CalendarExtender>
                                        <asp:Image ID="Image1" runat="server" ImageUrl="~/Image/Calendar_scheduleHS.png" />
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        Employee Wise :
                                    </td>
                                    <td align="left">
                                        <asp:DropDownList ID="ddlEmpList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlEmpList_SelectedIndexChanged" CssClass="input">
                                        </asp:DropDownList>
                                    </td>
                                </tr>
                            </table>
                            <asp:Label ID="lblMsg" runat="server" Font-Bold="True" ForeColor="Red" ></asp:Label>
                            <br />

 Other Asp.net web server control Post :


Comments