Name

DataGrid

Synopsis

The DataGrid control is, at its simplest, a data-bound list displayed in a table grid structure. It provides a rich set of functionality that makes it the most versatile data-bound control, including support for selection, editing, deleting, paging, and sorting.

Columns can be added to a DataGrid in two ways. First, if the AutoGenerateColumns property is True, a BoundColumn will be created for every column in the data source specified by DataSource. Alternatively, you can define columns by adding nested tags in the .aspx file. (If you mix both approaches, the automatically generated columns will always be added last.) Columns can be BoundColumn, ButtonColumn, EditCommandColumn, HyperLinkColumn, or TemplateColumn controls (each of which are described separately in this namespace). The order that the columns appear is determined by the order the column tags are listed in the .aspx, and you can manipulate them programmatically through the Columns collection. Note that this collection does not contain automatically generated columns—only ones that have defined templates.

The DataGrid has a number of properties that allow you to control its appearance. You can set TableItemStyle objects for various properties, including footers, headers (used automatically for column titles), and items. (The corresponding DataGrid properties end with the word “Style.”) You can also use the ShowHeader and ShowFooter properties to configure whether headers and footers will be displayed. ...

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.