Programming Microsoft ASP.NET 4 - Dino Esposito [250]
Finally, because the ListView control inherits from WebControl, it features a bunch of user-interface properties, including Style, CssClass, SkinID, Visible, and EnableTheming.
Note
The ListView control lacks the usual ton of style properties that characterize all other view controls in ASP.NET. The output of the ListView control can be styled at your leisure, but only by using cascading style sheets (CSS) directly, without even the mediation from ASP.NET themes.
This is intentional for a number of reasons. First, the control benefits from the momentum that CSS-based layouts are gaining in the industry. Second, Microsoft Visual Studio comes with a CSS editor through which editing and attaching styles to HTML elements is a breeze. Finally, the extreme flexibility of the markup generated by the ListView control would be hindered in several ways by ASP.NET themes. Themes work with entire ASP.NET controls, whereas the ListView control is an ASP.NET control that generates its output based on a template that is, when all is said and done, made of pure HTML you control at a fine-grained level.
Events of the ListView Control
The ListView control has no specific methods worth mentioning. Table 11-3 lists the events that the control fires during its life cycle.
Table 11-3. Events of the ListView Class
Event
Description
ItemCanceling
Occurs when the user requests a cancel operation, but before the control cancels the ongoing insert or edit operation.
ItemCommand
Occurs when the user clicks on any buttons found in the body of the control.
ItemCreated
Occurs when a new item in the ListView control is being created.
ItemDataBound
Occurs when an item is bound to its data.
ItemDeleting, ItemDeleted
The two events occur before and after, respectively, the deletion of an item. The operation is requested by the interface of the ListView control.
ItemEditing
Occurs when an edit operation is requested, but before the ListView switches to the edit template.
ItemInserting, ItemInserted
The two events occur before and after, respectively, the insertion of an item. The operation is requested by the interface of the ListView control.
ItemUpdating, ItemUpdated
The two events occur before and after, respectively, the update of an item. The operation is requested by the interface of the ListView control.
LayoutCreated
Occurs when the layout template is created.
PagePropertiesChanging, PagePropertiesChanged
The two events occur before and after, respectively, the properties of a page of data in the ListView control change. A page of data is the set of items that form a page in a paged ListView control. Page properties include page size and start row index.
SelectedIndexChanging, SelectedIndexChanged
The two events occur before and after, respectively, the ListView control handles the selection of a displayed item and switches to the selected-item template.
Sorting, Sorted
The two events occur before and after, respectively, the associated data source is sorted.
As you can see, most of the events are related to the life cycle of individual data items. You can control when an item is created, deleted, inserted, or edited. Events fire before and after a given operation is accomplished. So you find doing/done pairs of events for each fundamental operation, such as ItemInserting/ItemInserted or ItemDeleting/ItemDeleted events. You can determine which item type is being created by using the ItemType property on the event data structure. Feasible values are DataItem, InsertItem, and EmptyItem. These values belong to the ListViewItemType enumerated type.
The ListView