Learning Resources
 

Introducing the FormView Control


The FormView control gives you the ability to work with a single record from a data source, similar to the DetailsView control. The difference between the FormView and the DetailsView controls is that the DetailsView control uses a tabular layout where each field of the record is displayed as a row of its own. In contrast, the FormView control does not specify a pre-defined layout for displaying the record. Instead, you create a template containing controls to display individual fields from the record. The template contains the formatting, controls, and binding expressions used to create the form.

The FormView control is typically used for updating and inserting new records, and is often used in master/detail scenarios where the selected record of the master control determines the record to display in the FormView control. 

The FormView control relies on the capabilities of the data source control to perform tasks such as updating, inserting, and deleting records. The FormView control renders only a single data record at a time, even if its data source exposes multiple records.

The FormView control can automatically page over the data in its associated data source one record at a time, provided that the data is represented by an object implementing the ICollection interface, or that the underlying data source supports paging. The FormView control provides the user interface (UI) for navigating between records. To enable paging behavior, set the AllowPaging property to true and specify a PagerTemplate value.

The FormView control exposes several events that you can handle to execute your own code. The events are raised before and after insert, update, and delete operations of the associated data source control. You can also write handlers for the ItemCreated and ItemCommand events. 

NoteNote

The event model of the FormView control is similar to that of the GridView control. However, the FormView control does not support a selection event, because the current record is always the selected item.

--MSDN