|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
GridView Web Server Control Overview
A recurring task in software development is to display tabular data. ASP.NET provides a number of tools for showing tabular data in a grid, including thecontrol. With the GridView control, you can display, edit, and delete data from many different kinds of data sources, including databases, XML files, and business objects that expose data.
Using the GridView you can:
Automatically bind to and display data from a data source control.
Select, sort, page through, edit, and delete data from a data source control.
Additionally, you can customize the appearance and behavior of the GridView control by:
Specifying custom columns and styles.
Utilizing templates to create custom user interface (UI) elements.
Adding your own code to the functionality of the GridView control by handling events.
The GridView control is the successor to thecontrol. For details about differences between the controls, see .
The GridView control provides you with two options for binding to data:
Data binding using theproperty, which allows you to bind the GridView control to a data source control. This is the recommended approach because it allows the GridView control to take advantage of the capabilities of the data source control and provide built-in functionality for sorting, paging, and updating.
Data binding using theproperty, which allows you to bind to various objects, including ADO.NET datasets and data readers. This approach requires you to write code for any additional functionality such as sorting, paging, and updating.
When you bind to a data source using the DataSourceID property, the GridView control supports two-way data binding. In addition to the control displaying returned data, you can enable the control to automatically support update and delete operations on the bound data.
For more information, see.
You can specify the layout, color, font, and alignment of the GridView control's rows. You can specify the display of text and data contained in the rows. Additionally, you can specify whether the data rows are displayed as items, alternating items, selected items, or edit-mode items. The GridView control also allows you to specify the format of the columns. For information on formatting the GridView control, see the GridView class overview.
By default, the GridView 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 asor controls. You can also configure the GridView control to display a Delete button that users can click to delete the corresponding record from the data source.
The GridView 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 GridView control is bound to a read-only data source control.
You can customize the input controls that are used when a row is in edit mode using a template. For more information, see theclass.