Radio button in asp.net

 For Example: Write a program to demonstrate the use of radio button. 

Write a following program in asp file 

<html ><head runat="server">

    <title>Aryan Computers, Barshi </title>

</head>

<body>

    <p>

        <br />

    </p>

    <form id="form1" runat="server">

    <div style="margin-left: 80px">

            <asp:Label ID="Label1" runat="server" 

            style="font-weight: 700; font-size: medium" Text="Select Gender"></asp:Label>

        <br />

        <br />

        <asp:RadioButton ID="RadioButton1"  GroupName="g" runat="server" Text="Male" />

        <br />

        <br />

        <asp:RadioButton ID="RadioButton2" GroupName="g" runat="server" Text="Female" />

        <br />

        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Check" />

        <br />

        <asp:Label ID="Label2" runat="server"></asp:Label>

        <br />

        </div>

    </form>

</body>

</html>


 Write a following program in cs file 

public partial class Radio : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {    }

    protected void Button1_Click(object sender, EventArgs e)

    {

        Label2.Text = "";

      

        if (RadioButton1.Checked)

        {

            Label2.Text = "Your gender is " + RadioButton1.Text;

        }

        else 

 Label2.Text = "Your gender is " + RadioButton2.Text;  

    }

}

Output:




Comments

Popular posts from this blog

simple program C#

Regular Expression Validator Control in asp.net

two dimension array in C#