Export (0) Print
Expand All

TemplateField.ItemTemplate Property

Gets or sets the template for displaying an item in a data-bound control.

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

[<BrowsableAttribute(false)>]
[<PersistenceModeAttribute(PersistenceMode.InnerProperty)>]
[<TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection.TwoWay)>]
abstract ItemTemplate : ITemplate with get, set
[<BrowsableAttribute(false)>]
[<PersistenceModeAttribute(PersistenceMode.InnerProperty)>]
[<TemplateContainerAttribute(typeof(IDataItemContainer), BindingDirection.TwoWay)>]
override ItemTemplate : ITemplate with get, set

Property Value

Type: System.Web.UI.ITemplate
A System.Web.UI.ITemplate-implemented object that contains the template for displaying an item in a TemplateField. The default is a null reference (Nothing in Visual Basic), which indicates that this property is not set.

Use the ItemTemplate property to specify the custom content displayed for the items in a TemplateField object. Define the content by creating a template that specifies how the items are rendered.

NoteNote

You can optionally define the AlternatingItemTemplate property in combination with the ItemTemplate property to create a different appearance for every other item in the data-bound control.

To specify a template, first place opening and closing <ItemTemplate> tags between the opening and closing tags of the <TemplateField> element. Next, add the custom content between the opening and closing <ItemTemplate> tags. The content can be as simple as plain text or more complex (embedding other controls in the template, for example).

To programmatically access a control defined in a template, first determine which TableCell object in the data-bound control contains the control. Next, use the Controls collection of the TableCell object to access the control. You can also use the FindControl method of the TableCell object to find the control, if the control has an ID property specified.

The following code example demonstrates how to use the ItemTemplate property to create a custom template for the items of a TemplateField field in a GridView control. The template displays the field's value in a RadioButtonList control.

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
Show:
© 2015 Microsoft