The “FormView” control is similar to the “DetailsView” control. The only difference is instead of rendering data as an HTML table, the “FormView” control uses templates that let you specify exactly how you want it to render the data. The following template choices are available for you in the “FormView” control:
- “EmptyItemTemplate”: Rendered if the data source is empty.
- “ItemTemplate”: Displays data in read-only mode.
- “EditItemTemplate”: Displayed when the FormView control is in Edit mode.
- “InsertItemTemplate”: Displayed when the FormView control is in Insert mode.
- “HeaderTemplate”: Displayed at the top of the control.
- “FooterTemplate”: Displayed at the bottom of the control.
- “PagerTemplate”: Displayed when paging is enabled.
The following sample code shows how you can display the data from the data source using the Eval method. Here a label is associated to a data-source field called lblName.
<asp:Label ID="lblName" runat="server" Text='<%# Eval("lastname") %>'/>
The following sample code shows how to bind a text box to the “lblName” field. Here the “Bind” is used instead of “Eval” as the binding should be two ways; for input and output.
A command button can also be associated within a template.
When you click the button, the command can be sent to the “FormView” control. The following are some of the commands available for you:
- “Edit”: The “FormView” control is in Edit mode and displays the “EditItemTemplate” template.
- “New”: The “FormView” control is in Insert mode and uses the “InsertItemTemplate”.
- “Update”: Updates the data source with changes made while in Edit mode.
- “Insert”: Inserts a row using data entered while in Insert mode.
- “Cancel”: Cancels Edit mode or Insert mode and disregards any changes.
« Previous Chapter
Next Chapter »
Table of Contents
Chapter 1 - The Code-Behind Model
Chapter 2 - App_Folders
Chapter 3 - Master Pages
Chapter 3.1 - How to create a Default Master Page
Chapter 3.2 - How to create a Master Page
Chapter 3.3 - How to create a Default Content Page
Chapter 4 - Data Controls
Chapter 4.1 - The SQL Data Source Control
Chapter 4.1.1 - Other Data Sources in ASP.NET 2.0
Chapter 4.2 - The GridView Control
Chapter 4.3 - The DetailsView Control
» Chapter 4.4 - The FormView Control
Chapter 5 - Login Controls
Chapter 6 - The Wizard Control
Chapter 7 - Navigation Control
Chapter 8 - Web Parts
Chapter 9 - Themes
Chapter 10 - The Web Site Administration Tool