Wednesday, 8 October 2014

How to Use RadioButton One Example in Asp.Net C#

No comments    
categories: , ,
RADIOBUTTON


The RadioButton control is used to display a radio button.


DEMO




                            Html Coding


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <tr><td></td><td>
            <asp:Label ID="Label1" runat="server" Text="Select Your Hobby"></asp:Label>
            </td></tr>
        <tr><td></td><td>
            <asp:RadioButton ID="RadioButton1"
                runat="server" AutoPostBack="True"  GroupName="A"
                 OnCheckedChanged="RadioButton1_CheckedChanged1" Text="Playing" />
            </td></tr>
        <tr><td></td><td>
            <asp:RadioButton ID="RadioButton2"
                 runat="server" AutoPostBack="True" GroupName="A"
                 OnCheckedChanged="RadioButton2_CheckedChanged" Text="Singing" />
            </td></tr>
        <tr><td></td><td>
            <asp:RadioButton ID="RadioButton3"
                 runat="server" AutoPostBack="True" GroupName="A"
                 OnCheckedChanged="RadioButton3_CheckedChanged" Text="Writing" />
            </td></tr>
        <tr><td></td><td>
            <asp:RadioButton ID="RadioButton4"
                runat="server" AutoPostBack="True" GroupName="A"
                 OnCheckedChanged="RadioButton4_CheckedChanged" Text="Reading" />
            </td></tr>
        <tr><td></td><td>
            <asp:RadioButton ID="RadioButton5"
                runat="server" AutoPostBack="True" GroupName="A"
                 OnCheckedChanged="RadioButton5_CheckedChanged" Text="Browsing" />
            </td></tr>
        <tr><td></td><td>
            <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
            </td></tr>


   </table>
      
    </div>
    </form>
</body>
</html>           

C# Coding



protected void RadioButton1_CheckedChanged1(object sender, EventArgs e)
    {
        Label2.Text = " your Hobby is Playing ";
    }
    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        Label2.Text = " your Hobby is Singing";
    }
   
   
    protected void RadioButton3_CheckedChanged(object sender, EventArgs e)
    {
        Label2.Text = " your  Hobby is Writing";
    }
  
    protected void RadioButton4_CheckedChanged(object sender, EventArgs e)
    {
        Label2.Text = "your Hobby is Reading";
    }
  
   
    protected void RadioButton5_CheckedChanged(object sender, EventArgs e)
    {
        Label2.Text = "your Hobby is Browsing";
    }





if you set it's GroupName property same for multiple radiobuttons then all radiobuttons with same name act as a single group. 



















                                        









                                                           


0 comments:

Post a Comment