Working with Data in ASP.NET 2.0 - Using the FormViews Templates
In the last two tutorials we saw how to customize the GridView and DetailsView controls’ outputs using TemplateFields. TemplateFields allow for the contents for a specific field to be highly customized, but in the end both the GridView and DetailsView have a rather boxy, gridlike appearance. For many scenarios such a gridlike layout is ideal, but at times a more fluid, less rigid display is needed. When displaying a single record, such a fluid layout is possible using the FormView control.
Unlike the DetailsView, the FormView is not composed of fields. You can’t add a BoundField or TemplateField to a FormView. Instead, the FormView is rendered using templates. Think of the FormView as a DetailsView control that contains a single TemplateField. The FormView supports the following templates:
- ItemTemplate - used to render the particular record displayed in the FormView
- HeaderTemplate - used to specify an optiona- header row
- FooterTemplate - used to specify an optiona- footer row
- EmptyDataTemplate - when the FormView’s DataSource lacks any records, the EmptyDataTemplate is used in place of the ItemTemplate for rendering the control’s markup
- PagerTemplate - can be used to customize the paging interface for FormViews that have paging enabled
- EditItemTemplate / InsertItemTemplate - used to customize the editing interface or inserting interface for FormViews that support such functionality
…
The ItemTemplate can be created by hand (through the declarative syntax) or can be autocreated by binding the FormView to a data source control through the Designer. This autocreated ItemTemplate contains HTML that lists the name of each field and a Label control whose Text property is bound to the field’s value. This approach also autocreates an InsertItemTemplate and EditItemTemplate, both of which are populated with input controls for each of the data fields returned by the data source control. If you want to autocreate the template, from the FormView’s smart tag add a new ObjectDataSource control that invokes the ProductsBLL class’s GetProducts() method. This will create a FormView with an ItemTemplate, InsertItemTemplate, and EditItemTemplate. From the Source view, remove the InsertItemTemplate and EditItemTemplate since we’re not interested in creating a FormView that supports editing or inserting yet. Next, clear out the markup within the ItemTemplate so that we have a clean slate to work from.
…
Website: static.asp.net | Filesize: 265kb
No of Page(s): 5
Click here to download Working with Data in ASP.NET 2.0 - Using the FormViews Templates.
Related Tutorial
Tags: .NET, web control
Comments
Leave a Reply