Jun 22, 2011

How to Create a RadioButton Control in Asp.Net

RadioButton is a server control use to display option similar to checkbox.

RadioButton control supports the following properties

RadioButton Example
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    protected void btnSubmit_Click(object sender, EventArgs e)
        if (rdlYes.Checked)
            lblResult.Text = rdlYes.Text;
        if (rdlNo.Checked)
            lblResult.Text = rdlNo.Text;
        if (rdlNone.Checked)
            lblResult.Text = rdlNone.Text;
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>RadioButton Example</title>
    <form id="form1" runat="server">
    Did you like my website?    
        <asp:RadioButton id="rdlYes" Text="Yes" GroupName="Source" Runat="server" />
        <asp:RadioButton id="rdlNo" Text="No" GroupName="Source" Runat="server" />
        <asp:RadioButton id="rdlNone" Text="None" GroupName="Source" Runat="server" />
    <asp:Button id="btnSubmit" Text="Submit" Runat="server" OnClick="btnSubmit_Click" />   
    <hr />    
    Answer: <asp:Label id="lblResult" Runat="server" />    

No comments:

Post a Comment