ListView.ItemTemplate Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets or sets the custom content for the data item in a ListView control.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

[<TemplateContainerAttribute(typeof(ListViewDataItem), BindingDirection.TwoWay)>]
abstract ItemTemplate : ITemplate with get, set
[<TemplateContainerAttribute(typeof(ListViewDataItem), BindingDirection.TwoWay)>]
override ItemTemplate : ITemplate with get, set

Property Value

Type: System.Web.UI.ITemplate

An object that contains the custom content for the data item in a ListView control. The default is null, which indicates that this property is not set.

Use the ItemTemplate property to define a custom user interface (UI) to display the data items. The ItemTemplate template is required by the ListView control. It usually contains controls to display the field values of a record. If you want to let users modify the data, you also usually add buttons to the ItemTemplate template that let the user select a record, switch to edit mode, or delete a record.

To specify the custom template declaratively, add an ItemTemplate element inside the ListView control. You can then add the contents of the template to the ItemTemplate element. To display the field values of the data source that is bound to the control, use a data-binding expression. For more information, see Data-Binding Expressions Overview.

To create buttons that perform the built-in select, delete, and edit operations, add a button control to the template. Set its CommandName property to one of the values listed in the following table.

Button type

CommandName value







The following example shows how to define a custom template for a data item in the ListView control.

System_CAPS_security Security Note

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.5
Return to top