asp.net.ph

FormView.ItemTemplate Property

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.

Syntax

<asp:formview ... >

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

</asp:formview>

Property Value

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.

Remarks

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.

Example

The following examples show several ways of using an ItemTemplate in a FormView in different scenarios.

FormView ItemTemplate Example
Run Sample | View Source
FormView with Default Paging
Run Sample | View Source
FormView with Nested GridView
Run Sample | View Source
See Also

FormView 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