JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Checkbox Lists

You can use a checkbox list control to display a number of checkboxes at once. (This is often useful when you want to bind data from a data source to checkboxes.) This control has an Items collection (inherited from the ListControl class) with members corresponding to checkboxes in the list. Each item in the Items collection is an object of the ListItem class (see "Using the ListItem Class" in this chapter), and you can use the ListItem class's Value, Text, and Selected properties to work with the individual checkboxes in the list, like this: CheckBoxList1.Items(5).Selected. To find out which checkboxes are checked, you can loop through the list and test the Selected property of each item.


You also can use the SelectedItem or SelectedIndex properties in checkbox lists, but note that these lists can support multiple selections. If multiple items are selected, the SelectedItem and SelectedIndex properties hold the selected item with the lowest index value, and the index value of the selected item with the lowest index value, which tells you nothing about the other selected items. You usually use the SelectedItem or SelectedIndex properties with radio button lists, coming up in this chapter, which only support a single selected item.

You can specify the way the list is actually displayed by using the RepeatLayout and RepeatDirection properties. For example, 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.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor