.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
sritaa
Sandeep Singh
Melody Anderson
Sharad
Eminent IT

  

RadioButtonList Control

   
 
     


Introduction :

RadioButtonList Control is used for selecting one predefined (available in RadioButtonList) value. That means user can be able to select only one a time. For eg., it is useful for selecting the User Sex , Highest Qualification etc., ASP.NET RadioButtonList itself is a class like other controls which are present under System.Web.UI.WebControls namespace.

RadioButtonList Control is used for selecting one predefined (available in RadioButtonList) value. That means user can be able to select only one a time. For eg.,  it is useful for selecting the User Sex , Highest Qualification etc.,
ASP.NET RadioButtonList  itself is a class like other controls which are  present under System.Web.UI.WebControls namespace.

Important Properties of Asp.NET Webserver  RadioButtonList control are given below. You can Set /Get these properties  at Design time or at Runtime.

AutoPostBack -  Accept Boolean Value  - If True, then page will submit to the server if the index of the Radiobutton is changed

CausesValidation -  Accept Boolean Value - Used to Validate the page when RadioButton click event fires.

DataTextField - Accept String Value - Used to set the column Name from  the DataSource which user Can see (eg., Name).

DataValueField - Accept String Value - Used to set the column Name from  the DataSource which user Can not see (eg.,  ID).

Enabled - Accept Boolean Value- Used to Get/Set  Radio button Enabled

Height - Accept IntergerValue  -  Used to Set/Get height of the RadioButton

RepeatColumns - Accept Interger Value - Used to set how Many RadioButtons  you want to display in one line.

RepeatDirection - Enumerator - "Vertical" or "Horizontal"

Width - Accept IntergerValue -  Used to set the width of the RadioButton

Events available in Asp.Net Webserver RadioButtonList Control are:

DataBound - This event will fire when you call the assigned  dataSource property and you write this line of code to bind your RadioButtonList

myRadioButtonList.DataBind();//myRadioButtonList is the id of your RadioButtonList;

SelectedIndexChanged - This event will fire when user has changed  his/her selection and RadioButtonList's "AutoPostBack" property is set to true;

Lets See an example

Your .aspx code will look like this for a WebServer Control RadioButtonList

<asp:RadioButtonList ID="myRadioButtonList" runat="server" Width="104px"

            AutoPostBack="True" ondatabound="myRadioButtonList_DataBound"

            onselectedindexchanged="myRadioButtonList_SelectedIndexChanged">

        </asp:RadioButtonList>

Full Html Code used in attched example

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

 

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

 

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

<head runat="server">

    <title>RadioButtonList Example - www.DotNetSpark.com</title>

</head>

<body>

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

    <div>

   

        <asp:Label ID="lblPageMessage" runat="server" Text="RadioButtonList Example"></asp:Label>

        <br />

        <br />

        <asp:RadioButtonList ID="myRadioButtonList" runat="server" Width="104px"

            AutoPostBack="True" ondatabound="myRadioButtonList_DataBound"

            onselectedindexchanged="myRadioButtonList_SelectedIndexChanged">

        </asp:RadioButtonList>

     <br />

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

    </div>

    </form>

</body>

</html>

And to assign value to the textbox programmatically in Page_Load  Event form the .cs file

And to assign value to the textbox programmatically in Page_Load  Event form the .cs file

 

myRadioButtonList.DataSource = MyDataTable(); //DataTable as Data Source

myRadioButtonList.DataTextField = "SomeText";//Column name from Table for user to see

myRadioButtonList.DataValueField = "ID"; //Column name hidden to the user

myRadioButtonList.DataBind();// Bind the DataTable the RadioButton Control

 
Other Tutorials in the same Category:
      
  • CheckBoxList Control      
  • Button Control      
  • Calendar Control      
  • CheckBox Control      
  • DropDownList Control or Combobox      
  • FileUpload Control      
  • Hidden Field Control      
  • ImageButton Control      
  • Link Button Control      
  • ListBox Control      
  • Literal Control      
  • RadioButton Control      
  • RadioButtonList Control      
  • TextBox Control

  •  
         
     
    Return to Main Index Page


    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend