.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

  

CheckBoxList Control

   
 
     


Introduction :

CheckBoxList Control is used for selecting one or more predefined (Available in CheckBoxList) value. That means user can able to select only one or more values at a time. For eg., it is useful for selecting the User Interest , Things user is holding etc., ASP.NET CheckBoxList itself is a class like other controls which are present under System.Web.UI.WebControls namespace.

CheckBoxList Control is used for selecting one or more predefined (Available in CheckBoxList) value. That means user can able to select only one or more values at a time. For eg., it is useful for selecting the User Interest , Things user is holding etc.,
ASP.NET  CheckBoxList itself is a class like other controls which are present under System.Web.UI.WebControls namespace.

Important Properties of Asp.NET Webserver  CheckBoxList 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 dropdown is changed.

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

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

DataVaueField - 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 button Enabled

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

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

RepeatDirection - Enumerator - "Vertical" or "Horizontal" .

Width - Accept IntergerValue -  Used to set the width of the Button.

 

Events available in Asp.Net Webserver CheckBoxList Controls are:

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

myCheckBoxList.DataBind();//myCheckBoxList is the id of your CheckBoxList;

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

Lets See an example:

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

<asp:CheckBoxList ID="myCheckBoxList" runat="server" AutoPostBack="True"

            ondatabound="myCheckBoxList_DataBound"

            onselectedindexchanged="myCheckBoxList_SelectedIndexChanged" RepeatColumns="3"

            RepeatDirection="Horizontal">

        </asp:CheckBoxList>


Full Html Code used in attached 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>CheckBoxList Example - DotNetSpark.com</title>

</head>

<body>

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

    <div>

   

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

        <br />

        <br />

        <asp:CheckBoxList ID="myCheckBoxList" runat="server" AutoPostBack="True"

            ondatabound="myCheckBoxList_DataBound"

            onselectedindexchanged="myCheckBoxList_SelectedIndexChanged" RepeatColumns="3"

            RepeatDirection="Horizontal">

        </asp:CheckBoxList>

        <br />

        <br />

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

   

    </div>

    </form>

</body>

</html>


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

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

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

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

myCheckBoxList.DataBind();// Bind the DataTable the CheckBoxList 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