JavaScript Editor Javascript validator     Javascripts

Main Page


Previous Section Next Section

10.1 Shared Properties and Collections

Before delving into the specifics of each list-bound control, this chapter will examine the features all three controls share in common.

10.1.1 DataSource

All the list-bound controls have a DataSource property. This property defines the source for data binding, as you've seen earlier with other controls. A DataSource can be any object that implements the System.Collections.ICollection interface: an array, a dataset, or some other homogeneous collection of objects. Often, the data source will be a System.Data.Dataview object, as discussed in Chapter 11. For simplicity, in this chapter you will continue to use an ArrayList object, though you can use any object that implements System.Collections.ICollection, such as a HashTable or an Array object.

10.1.2 Items

The three list-bound controls also contain an Items property that returns a collection of objects representing an item (row) in the data source collection. You use the Items collection to manipulate the items in the list control programmatically.

The Repeater control's Items property returns a collection of RepeaterItem objects, the DataList control's Items property returns a collection of DataListItem objects, and the DataGrid control's Items property returns DataGridItem objects.

The Items collection has an ItemType property that returns an enumerated ListItemType. The members of the ListItemType enumeration are shown in Table 10-2.

Table 10-2. Members of the ListItemType enumeration

List item type

Purpose

AlternatingItem

Every other item

EditItem

Used for in-place editing; see Chapter 13

Footer

Display footer for control

Header

Display header information for control

Item

Displays information about data item

Pager

Display paging information

SelectedItem

The item the user has selected

Separator

Appears between items

Manipulation of the various types of members of the Items collection will be demonstrated throughout the rest of this chapter.

All of the list-bound controls follow the explicit binding method. When its DataBind method is called, the list-bound control enumerates its data source, creating DataListItems and initializing them from the DataSource items. The DataListItem objects are then added to the list-bound control's Items collection. Because this happens only on demand, there are fewer round trips to the server than might otherwise be expected.

    Previous Section Next Section


    JavaScript Editor Javascript validator     Javascripts 




    ©