The DetailsView and FormView controls enable us to display a single data item that is a single database record at a time. Both controls enable display, edit, insert and deletion of data items such as database records but with a condition -single data item at a time. Both the controls, DetailsView and FormView controls support page forward and backward traversing (page forward and backward traversing allow us to move through the records one at a time both in the forward and backward direction).
Each of these two controls render the user interface in its own unique way. This is the major difference between the two controls. The difference is that the FormView control uses a template to display a single database record at a time and the DetailsView control displays a single database record as HTML table.
The DetailsView control is typically used for updating and inserting new records often in a master/detail scenario. In such a scenario, the selected record of the master control (GridView or ListBox control) determines the record to be displayed in the DetailsView control. For instance, in an ERP application, we use the GridView control to display pending sales order details and the DetailsView control to display the selected single sales order details. We use the <BoundField> elements or <TemplateField> elements to render the DetailsView control. The DetailsView control displays each field of a record as a table row.
The FormView control
The FormView control is designed to display a single data item (single database record) from a data source, for example Sql server database. Unlike the DetailsView control, templates have to be used in the FormView control to display data. The FormView control renders all fields of a single record in a single table row. While using templates, we can place any control such as dropdownlist, checkbox and even we can place tables and rich control like GridView etc. Compared to the DetailsView control, the formView control gives more flexibility over the rendering of fields. This form of rendering data enables more control over the layout of the fields. Using the FormView control is more complex as compared to the DetailsView control. Note that we cannot use <BoundField> elements to render the FormView control.
- The DetailsView control is easier to work with.
- The FormView control provides more control over the layout.
- The FormView control uses only the templates with databinding expressions to display data. The DetailsView control uses <BoundField> elements or <TemplateField> elements.
- The FormView control renders all fields in a single table row whereas the DetailsView control displays each field as a table row.