asp.net.ph

TemplateField.ItemTemplate Property

System.Web.UI.WebControls Namespace   TemplateField Class


.NET Framework version 2.0

Specifies the template to use for displaying a row of data in a TemplateField control.

Syntax

<asp:templatefield ... >

   <itemtemplate>
      ... template definition here
   </itemtemplate>

</asp:templatefield>

Property Value

An ITemplate interface that defines how the TemplateField control is rendered when in display ( or read-only ) mode.

The property is read/write with no default value.

Remarks

Use the ItemTemplate to define the layout of elements in the TemplateField control when displaying a row of data.

To specify a template for displaying a row of data, declare an <ItemTemplate> element between the opening and closing tags of the control. You can then list the contents of the template between the opening and closing <ItemTemplate> ... </ItemTemplate> tags.

In the ItemTemplate, declare the appropriate HTML or server control you intend to use ( Label, HyperLink, Image, etc. ) and set their data-binding expressions to evaluate to a field in the parent control's data source.

To dispaly data in the ItemTemplate, you must associate a field with a control using the Eval method, as shown in the following example.

<img runat = "server" 
   src='<%# Eval ( "ProductID", "~/shared/images/gear/{0}.jpg" ) %>' 
   alt='<%# Eval ( "Model" ) %>'
   width=220 height=220 border=0>

This allows the parent control to automatically display the field values in the associated control.

To control the style of the row, use the ItemStyle property of the TemplateField control.

Example

The following examples show several ways of using an ItemTemplate in a TemplateField to display a column with custom layout in a GridView control.

Disabling AutoGenerateColumns in a GridView
Run Sample | View Source
Dynamically Generated ButtonField ImageButtons
Run Sample | View Source
GridView SelectedDataKey Example
Run Sample | View Source
See Also

TemplateField Members   EditItemTemplate   InsertItemTemplate Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph