HOME

ASP.NET Tutorial
ASP.NET HOME
ASP.NET Intro
ASP.NET vs ASP
ASP.NET Install
ASP.NET Pages
ASP.NET Controls
ASP.NET Events

References
HTML Controls
Web Controls
Validation Controls
Download XMLSpy here
Please visit our sponsors !

CheckBoxList Control

Back

Definition and Usage

The CheckBoxList control is used to create a multi-selection check box group.

Each selectable item in a CheckBoxList control is defined by a ListItem element!

Tip: This control supports data binding!


Properties

Property Description
AutoPostBack A Boolean value that specifies whether the form should be posted immediately after one of the items changes select status or not. Default is false
CellPadding The space, in pixels, between the cell walls and the check box group
DataSource The data source to use
DataTextField A field in the data source to be displayed in the check box group
DataValueField A field in the data source that specifies the value of each selectable item in the check box group
id A unique id for the control
OnSelectedIndexChanged The name of the function to be executed when one of the items changes select status
RepeatColumns The number of columns to use when displaying the check box group. Default is "1"
RepeatDirection Specifies whether the check box group should be repeated horizontally or vertically. Legal values are "Horizontal" and "Vertical". Default is Vertical
RepeatLayout The layout of the check box group. Can be "Table" or "Flow". Default is Table
runat Specifies that the control is a server control.  Must be set to "server"
TextAlign On which side of the check box the text should appear (right or left)

Example 1

In the following example we declare one CheckBoxList control in an .aspx file. Then we create an event handler for the SelectedIndexChanged event. The selectable list contains six check boxes. When a user checks one of the boxes, the page is immediately posted back to the server, and the Check_Clicked subroutine is executed. The subroutine loops through the control's Items collection and tests each item's Selected property. The selected items are then displayed in the Label control:

<script runat="server">
  Sub Check_Clicked(sender As Object, e As EventArgs)
    dim i
    mess.Text="<h3>Selected Item(s)</h3>"
    for i=0 to check1.Items.Count-1
      if check1.Items(i).Selected then
        mess.Text+=check1.Items(i).Text + "<br />"
      end if
    next
  End Sub
</script>
<html>
<body>
<form runat="server">
<asp:CheckBoxList id="check1" AutoPostBack="True"
TextAlign="Right" OnSelectedIndexChanged="Check_Clicked"
runat="server">

<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>

</asp:CheckBoxList>
<br />
<br />
<asp:label id="mess" runat="server"/>
</form>
</body>
</html>


Back

Jump to: Top of Page or HOME or Printer Friendly Printer friendly page


Search W3Schools:


What Others Say About Us

Does the world know about us? Check out these places:

Dogpile Alta Vista MSN Google Excite Lycos Yahoo Ask Jeeves


We Help You For Free. You Can Help Us!


W3Schools is for training only. We do not warrant its correctness or its fitness for use. The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.

Copyright 1999-2002 by Refsnes Data. All Rights Reserved


Validate How we converted to XHTML Validate

ASPHits
Active Server Pages Resource Web Site


Your own Web Site?

Read W3Schools
Hosting Tutorial



$15 Domain Name
Registration
Save $20 / year!



Advertise
at W3Schools

Only 0.5 CPM



SELECTED LINKS

University Online
Master Degree
Bachelor Degree


Web Software

The Future of
Web Development


Jobs and Careers

Web Security
Web Statistics
Web Standards


PARTNERS

W3Schools
TopXML
VisualBuilder
XMLPitstop
DevelopersDex
DevGuru
Programmers Heaven
The Code Project
Tek Tips Forum
ZVON.ORG
TopXML Search