FormView

The FormView control gives you the ability to work with a single record from a data source, similar to the DetailsView. 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 Cc295401.xtlink_newWindow(en-us,Expression.40).png in the MSDN library.

To add a FormView control to a page

  • Drag the FormView control from the Toolbox panel 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, see Configure 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 panel, 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 Cc295401.xtlink_newWindow(en-us,Expression.40).png in the MSDN library.

See also

Concepts

Working with ASP.NET sites
ASP.NET Data controls
DataList
DetailsView
GridView
Repeater

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.