Home .NET Controls How to use radio button in asp.net
Author:

How to use radio button in asp.net.

Here is a sample code.

DOWNLOAD SAMPLE PROJECTS

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!-- HOW TO USE RADIO BUTTON IN ASP.NET -->

 

<script runat="server">

Sub submit(ByVal Sender As Object, ByVal e As EventArgs)

If Milk.Checked Then

Label1.Text = "You selected " & Milk.Text

ElseIf Orange.Checked Then

Label1.Text = "You selected " & Orange.Text

ElseIf Apple.Checked Then

Label1.Text = "You selected " & Apple.Text

ElseIf Banana.Checked Then

Label1.Text = "You selected " & Banana.Text

End If

End Sub

</script>

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

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

<h1>

Select your favorite Food:</h1>

<br />

<br />

<asp:RadioButton ID="Milk" Text="Red" Checked="True" GroupName="food" runat="server" />

<br />

<asp:RadioButton ID="Orange" Text="Orange" GroupName="food" runat="server" />

<br />

<asp:RadioButton ID="Apple" Text="Apple" GroupName="food" runat="server" />

<br />

<asp:RadioButton ID="Banana" Text="Banana" GroupName="food" runat="server" />

<br />

<br />

<asp:Button ID="btnSubmit" Text="Submit" OnClick="submit" runat="server" />

<p>

<asp:Label ID="Label1" runat="server" /></p>

</form>

</body>

</html>



Comments (0)
Write comment
Your Contact Details:
Comment:
Security
Please input the anti-spam code that you can read in the image.

"