DetailsView control

The DetailsView control gives you the ability to display, edit, insert, or delete a single record at a time from its associated data source. By default, the DetailsView control displays each field of a record on its own line. The DetailsView control is typically used for updating and inserting new records, often in a master/detail scenario where the selected record of the master control determines the record to display in the DetailsView control. The DetailsView control displays only a single data record at a time, even if its data source exposes multiple records. The DetailsView control does not support sorting.

To add a DetailsView control to a page

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

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

To bind the DetailsView control to a data source

  1. In Design view, right-click the DetailsView 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.

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

To apply basic formatting schemes to the DetailsView control

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

  2. On the Common DetailsView 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 DetailsView 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 DetailsView 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 DetailsView. You can also interactively format the DetailsView control area templates.

By default, the DetailsView control displays data in read-only mode. However, the control also supports an edit mode in which it displays a row that contains editable controls such as the TextBox control or CheckBox control. You can also configure the DetailsView control to display a Delete button that users can click to delete the corresponding record from the data source.

The DetailsView control can automatically perform editing and deleting operations with its associated data source, which allows you to enable editing behavior without writing code. Alternatively, you can control the process of editing and deleting data programmatically, such as in cases where the DetailsView control is bound to a read-only data source control.

To specify DetailsView control data editing options

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

  2. Check the functionality you want:

    • Enable paging — Displays only a subset of the records on a page and allows a user to move from page to page to display more records. For more information, see Paging in a DetailsView Web Server Control in the MSDN library.

    • Enable sorting — Allows a user to sort the records from the database.

    • Enable editing — Allows a user to make changes to the records.

    • Enable deleting — Allows a user to delete rows from the database.

    • Enable selection — Allows a user to select rows. You specify the look of selected rows by setting the styles in the SelectedRowStyle group in the Properties task pane.

For more information, see DetailsView Web Server Control Overview in the MSDN library.

Community Additions