Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [248]

By Root 5614 0
is fully template based and allows you to control all aspects of the user interface via templates and properties. ListView operates in a way that closely resembles the behavior of existing data-bound controls, such as FormView or DataList. However, unlike these controls, the ListView control never creates any user-interface layout. Every markup tag that the control generates is entirely under the developer’s control, including header, footer, body, item, selected item, and so on.

The ListView control binds to any data source control and executes its set of data operations. It can page, update, insert, and delete data items in the underlying data source as long as the data source supports these operations. In most cases, no code is required to set up any of these operations. If code is required, you can also explicitly bind data to the control using the more traditional DataSource property and related DataBind method.

The rendering capabilities of the ListView control make it suitable for publishing scenarios where a read-only, but compelling, user interface is needed. The control also works great in editing scenarios even though it lacks some advanced features such as input validation or made-to-measure edit templates for particular types of data or foreign keys.

The ListView Object Model


Data binding and template support are the principal characteristics of the ListView control that are most obvious when you examine the control’s programming model. From the programmer’s perspective, the key thing to be aware of is that you need to specify at least two template properties for the ListView control to compile and work. They are LayoutTemplate and ItemTemplate. In addition, the overall layout template must expose a connection point to the control so that bound records can be merged into the final markup.

Properties of the ListView Control


The ListView layout supports several properties that fall into two main categories: behavior and templates. It also supports a few general ASP.NET control properties and binding properties. Table 11-1 lists the behavioral properties.

Table 11-1. ListView Behavior Properties

Property

Description

ConvertEmptyStringToNull

Boolean value, indicates whether empty string values are automatically converted to null values when any contents edited in the control’s interface are saved back to the data source.

EditIndex

Gets or sets the index of the item being edited.

EditItem

Gets the item that is currently in edit mode within a ListView control. The type of the item is ListViewItem.

GroupItemCount

Gets or sets the number of items to display per group.

GroupPlaceholderID

Gets or sets the ID of the page element where the content for the ListView groups will be placed. The placeholder must be a server element flagged with the runat attribute. If a value for this property is not specified, a value of groupPlaceholder is assumed.

InsertItem

Gets the item that is currently in insert mode within a ListView control. The type of the item is ListViewItem.

InsertItemPosition

Gets or sets the location of the insert template. Feasible values are defined in the InsertItemPosition enumerated type: FirstItem, LastItem, or None.

ItemPlaceholderID

Gets or sets the ID of the page element that will host data-bound items. The placeholder must be a server element flagged with the runat attribute. If this property is not specified, a value of ItemPlaceholder is assumed.

Items

Gets the collection of bound items.

SelectedDataKey

Gets the data-key array of values for the selected item. This value coincides with SelectedValue except when multiple key fields are used.

SelectedIndex

Gets or sets the index of the currently selected item.

SelectedValue

Gets the data-key value of the first key field of the selected item.

SortDirection

Gets the sort direction of the field or fields being sorted.

SortExpression

Gets the sort expression that is associated with the field or fields being sorted.

Two properties in this list are somewhat new even to seasoned

Return Main Page Previous Page Next Page

®Online Book Reader