Comparing the GridView and DataGrid Web Server Controls
Thecontrol is the successor to the control. Like the DataGrid control, the GridView control was designed to display data in an HTML table. When bound to a data source, the DataGrid and GridView controls each display a row from a as a row in an output table.
Both the DataGrid and GridView controls are derived from theclass. Although it has a similar object model to that of the DataGrid control, the GridView control also has a number of new features and advantages over the DataGrid control, which include:
Richer design-time capabilities.
Improved data source binding capabilities.
Automatic handling of sorting, paging, updates, and deletes.
Additional column types and design-time column operations.
A Customized pager user interface (UI) with theproperty.
Differences between the GridView control and the DataGrid control include:
Different custom-paging support.
Different event models.
Improved Design-Time Capabilities
Sorting, paging, and in-place editing of data requires additional coding when using the DataGrid control. The GridView control enables you to add sorting, paging, and editing capabilities without writing any code. Instead, you can automate these tasks, along with other common tasks such as data binding to a data source, by setting properties on the control.
If you are working in a designer, such as Microsoft Visual Studio, you can take advantage of designer features built into the GridView control. The GridView control includes support for a smart tag panel that provides a convenient interface for performing common tasks, such as setting properties and launching template editing.
Improved Data Source Binding Capabilities
Typically acontrol, a control, or a collection, such as an , an , or some other class in the namespace, is assigned to the DataSource property of either the DataGrid control or the GridView control. The DataGrid control and the GridView control can bind any object that implements the or interface.
While the DataGrid control can declaratively bind acontrol, it can do so only for data selection. Sorting, paging, updates, and deletions must be coded manually. The GridView control supports a property that takes any object that implements the interface and can, therefore, take advantage of the data source control's sorting, paging, updating, and deleting capabilities, for example, the control.
Additional Column Types
The GridView control supports the following column types:, , , , and .
Built-In and Custom Paging Support
The DataGrid control requires additional coding for paging. The GridView control automatically supports paging by setting theproperty. The PagerSettings property supports four modes: (default), , , and . The Numeric mode displays numbered page links instead of "next/prev" links, and the NumericFirstLast option adds first and last page links. The GridView control's property can be used to set styles and the position of the pager.
Additionally, you can customize the pager buttons for the GridView control using a PagerTemplate.
Custom paging support in the GridView is supplied by the bound data source control as opposed to themechanism supplied by the DataGrid control.
Expanded Event Model
The DataGrid and the GridView controls have different event models.
The DataGrid control raises single events for operations, while the GridView control is capable of both pre-operation and post-operation events. The GridView control supports theevent that occurs when a field is sorted. Note that this sorting event occurs before the GridView control automatically handles the sort operation, giving you the opportunity to examine or change the property, or cancel this operation by setting the property to true on the passed event arguments.
The GridView control supports theevent that occurs after the GridView control completes the sort operation, giving you the opportunity to change or format the result of the sort operation. In comparison, the DataGrid control supports the event that occurs when a column is sorted. Similarly, the GridView control supports and events that occur before and after the GridView control has automatically handled the update operation. In comparison, the DataGrid control supports the event that occurs when the Update button is clicked for an item in the grid.
For more information on GridView events, see.