Adding a FormView control to the page
Data Binding with the FormView Control
The FormView control provides you with these options for binding to data:
Data binding using theproperty, which allows you to bind the FormView control to a data source control. This is the recommended approach because it allows the FormView control to take advantage of the capabilities of the data source control and to provide built-in functionality for updating and paging.
Data binding using theproperty, which allows you to bind to various objects, including ADO.NET datasets and data readers. This approach requires you to write the code for any additional functionality such as updating and paging.
When you bind to a data source using the DataSourceID property, the FormView control supports two-way data binding. In addition to the control displaying data, you can enable the control to automatically support insert, update, and delete operations on the bound data.
Creating the FormView Control User Interface
You build the user interface (UI) for the FormView control by creating templates. You specify different templates for different actions. You create antemplate for display, insert, and edit modes. You can control paging using a PagerTemplate template, and you can customize the FormView control's header and footer using a and , respectively. Using an , you can also specify a template to display when the data source does not return any data.
The item templates that you create for the FormView control specify the content of the control. As with the DetailsView control, you can also customize the display format of the FormView control by using style properties such as the, , , , , , and properties.
The following example shows a simple ASP.NET page that uses a FormView control to display data.
<%@ Page language="C#" %> "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "https://www.w3.org/1999/xhtml" > "server">