NET Grid View control is the successor to the v1.x Data Grid, adding the ability to take advantage of specific capabilities of ASP. Whereas the v1.x Data Grid required a page developer to write custom code to handle simple operations such as paging, sorting, editing or deleting data, the Grid View control can automatically handle these operations provided its bound data source control supports these capabilities.The Grid View also offers some functionality improvements over the Data Grid, such as the ability to define multiple primary key fields, and some UI customization improvements, such as new field types and templating options.It also exposes a new model for page developers to handle or cancel events.
In the preceding example, the Grid View control reflected against the fields of the data records returned by Sql Data Source in order to dynamically generate the columns of the grid.
You can also specify explicit column fields to display by adding Data Control Field objects to the Grid View's Columns collection.
This allows you to specify exactly which columns to display and their relative order.
The following example demonstrates a collection of Bound Field and Check Box Field objects in the Grid View Columns collection.
Other field types that can be assigned to this collection are Image Field, Hyper Link Field, Command Field, Button Field, and Template Field.
One of the key advantages of the Grid View control over other data-bound controls is its ability to automatically take advantage of data source capabilities.
Instead of relying on page code to manually sort or page data, the Grid View control can perform these operations automatically as long as the data source is configured to support these operations.
The following example shows a Grid View control with sorting enabled.
You can also enable paging UI in the Grid View by setting the Allow Paging property to true.
The Grid View can automatically page over any return value from a data source that supports the ICollection interface.
The Data View returned by Sql Data Source when in Data Set mode supports this interface, so Grid View can page over the result.