10.1 Shared Properties and CollectionsBefore delving into the specifics of each list-bound control, this chapter will examine the features all three controls share in common. 10.1.1 DataSourceAll 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 ItemsThe 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 Items collection has an ItemType property that returns an enumerated ListItemType. The members of the ListItemType enumeration are shown in Table 10-2.
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. |