JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Using the CheckBoxList Class

Checkbox list controls create multiselection checkbox groups. You can create these at run time by binding these controls to a data source. Here is the hierarchy of the CheckBoxList class:

Object
   Control
      WebControl
         ListControl
            CheckBoxList

To find out which items are checked in this control, you can loop through the list and test the Selected property of each item. Each item in the checkbox list's Items collection (inherited from the ListControl class) is an object of the ListItem class (see "Using the ListItem Class" in this chapter). You can use the ListItem class's Value, Text, and Selected properties to work with the checkboxes in the list, like this: CheckBoxList1.Items(5).Selected. And, as discussed in the In Depth section of this chapter, you can specify the way the list is displayed using the RepeatLayout and RepeatDirection properties. If RepeatLayout is set to RepeatLayout.Table (which is the default), the list is drawn in an HTML table. If it is set to RepeatLayout.Flow, on the other hand, the list is drawn without a table. And by default, RepeatDirection is set to RepeatDirection.Vertical. Setting this property to RepeatDirection.Horizontal draws the list horizontally.

You can find the notable public properties of CheckBoxList objects in Table 16.7, the notable methods in Table 16.8, and the notable public events in Table 16.9. Note that as with other Web server controls, I am not listing the notable properties, methods, and events this class inherits from the Control and WebControl classes—you can find them in Chapter 15, Tables 15.1 to 15.5. And this class is also based on the ListControl class—you can find the properties and events (it has no non-in-herited methods) of that class in Tables 16.4 and 16.5.

Table 16.7: Noteworthy public properties of CheckBoxList objects.

Property

Means

CellPadding

Gets/sets the distance between the checkbox and the table cell that contains it, in pixels.

CellSpacing

Gets/sets the distance between the table cells the checkboxes are displayed in, in pixels.

RepeatColumns

Gets/sets the number of columns in the checkbox list.

RepeatDirection

Gets/sets whether checkboxes are arranged vertically or horizontally.

RepeatLayout

Gets/sets the checkbox layout.

TextAlign

Gets/sets the alignment of the caption text for the checkboxes.

Table 16.8: Noteworthy public methods of CheckBoxList objects.

Method

Means

DataBind

Binds the checkbox list to a data source.

Dispose

Disposes of the checkbox list.

Table 16.9: Noteworthy public events of CheckBoxList objects.

Event

Means

DataBinding

Occurs when the checkbox list is bound to a data source.

Load

Occurs when the checkbox list is loaded.

Unload

Occurs when the checkbox list is unloaded.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor