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. For more information and an example, see Modifying Data Using a FormView Web Server Control in the MSDN library.

To add a FormView control to a page

  • Drag the FormView control from the Toolbox task pane to your page.

After you add a FormView control, you can specify a data source for the control.

To bind the FormView control to a data source

  1. In Design view, right-click the FormView control, and then click Show Common Control Tasks.

  2. On the Common DropDownList Tasks menu, click an existing data source or <New Data Source...> in the Choose Data Source dropdown.

  3. If you choose <New Data Source...>, configure a new data source in the Data Source Configuration Wizard. For more information, seeConfigure a data source by using a data bound control.

Customizing the FormView display

The easiest way to customize the FormView display is to use the AutoFormat option.

To apply basic formatting schemes to the FormView control

  1. In Design view, right-click the FormView control, and then click Show Common Control Tasks.

  2. On the Common FormView Tasks menu, click AutoFormat.

  3. In the AutoFormat dialog box, select one of the schemes in the Select a scheme list. The effect of the scheme on your FormView control is displayed in the Preview area.

  4. Click OK to apply the formatting scheme and close the dialog, or Apply to apply the formatting scheme without closing the dialog.

You can also customize each of the areas or states of the FormView by updating the collection of styles associated with the area. For example, in the Styles group in the Tag Properties task pane, you can customize the RowStyle, HeaderStyle and other collections of styles for an area of the FormView. You can also interactively format the FormView control area templates.

To interactively design the FormView templates

  1. In Design view, right-click the FormView control, and then click Show Common Control Tasks.

  2. On the Common FormView Tasks menu, click Edit Templates. This switches the Wizard into Template Editing Mode.

  3. In the Display dropdown, select the template you would like to edit.

  4. When you are finished designing your templates, on the Common FormView Tasks menu, click End Template Editing to return to the standard FormView design mode.

For more information about using the FormView control, see FormView Web Server Control Overview in the MSDN library.

See also

Concepts

ASP.NET overview

ASP.NET data controls overview

DataList control

DetailsView control

GridView control

Repeater control