ListView Example, ListView Control in ASP.NET C#

Most data-bound controls supplied with ASP.NET automatically enclose the displayed data with additional markup. As an example, the GridView control displays its data rendered inside of an HTML table (<table>), displaying each record of data bound to it as a table row (<tr>) and each record field as a cell within the row (<td>). While you can use TemplateField elements and other tools to customize the appearance of a GridView, the GridView's output will still be enclosed within a table element. But sometimes you want to have complete control over the appearance of the HTML markup generated by the data-bound controls. This is exactly where the ListView control comes into play. The ListView control does not automatically enclose its rendered output in any additional markup. Instead, it's your responsibility to specify the precise HTML rendered for the ListView control. You specify the precise markup using the ListView's built-in templates. Table 1 lists the templates supported by the ListView control.

ListView Template & Purpose
  • AlternatingItemTemplate : Display alternating items with different markup to help viewers distinguish consecutive items.
  • EditItemTemplate : Controls display when an item is in edit mode.
  • EmptyDataTemplate : Controls display when the ListView's data source returns no data.
  • EmptyItemTemplate : Controls the display for an empty item.
  • GroupSeparatorTemplate : Controls the content to display between groups of items.
  • GroupTemplate : Specifies a container object such as a table row, div, or span element for the content.
  • InsertItemTemplate : Specifies content to render when users insert an item.
  • ItemSeparatorTemplate : Controls the content to display between individual items.
  • ItemTemplate : Controls content to display for individual items.
  • LayoutTemplate : Specifies the root element that defines a container object, such as a table, div, or span element that surrounds content defined in the ItemTemplate or GroupTemplate.
  • SelectedItemTemplate : Specifies the content to display for the currently selected item.
Tags: ,
Hot on Web:


About author