System.Web.UI.WebControls Namespace FormView Class
.NET Framework version 2.0
Specifies the template to use for displaying a row of data in a FormView control.
<asp:formview ... >
<itemtemplate>
... template definition here
</itemtemplate>
</asp:formview>
An ITemplate interface that defines how the FormView control is rendered when in display ( or read-only ) mode.
The property is read/write with no default value.
Use the ItemTemplate to define the layout of elements in the FormView 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 controls you intend to use ( Label, Image, HyperLink, etc. ) and set their data-binding expressions to evaluate to a field in the data source.
To display 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>
At run time, the FormView automatically renders the field values in the associated controls.
To control the style of the row, use the RowStyle property.
The following examples show several ways of using an ItemTemplate in a FormView in different scenarios.
FormView Members EditItemTemplate InsertItemTemplate