the table data cells. The DataList makes things a bit easier by generating a single-
column table for us, but even so, the built-in functionality isn’t overwhelming.
Here, we’ll learn about two more controls that offer much more functionality
and make it very easy for you to create a table: GridView and DetailsView. These
controls, which form part of ASP.NET’s set of data controls, give developers
much more power and flexibility over presentation, as you’ll see in the next few
sections. The processes by which information within a table is presented,
formatted, and edited have been completely revamped with the GridView and
DetailsView controls.
GridView vs DataGrid
The GridView control supersedes the DataGrid control, which was the
star of all data-displaying controls in ASP.NET 1.0 and 1.1. The DataGrid
is still present in ASP.NET 2.0 for backwards-compatibility purposes, but
for any new development, the GridView is recommended. The DetailsView
control is new in ASP.NET 2.0 and doesn’t have a corresponding control in
earlier versions.
Using the GridView Control
The GridView control solves a problem that has plagued developers for years:
data presentation. The GridView control generates simple HTML tables, so in-
formation within a GridView is presented to the end user in a familiar, cleanly
formatted, tabular structure. Similar to the Repeater control, the GridView can
also automatically display all the content contained in an SqlDataReader on a
page, based on styles we set within its templates. However, unlike the Repeater
control, the GridView offers several more advanced features, such as sorting or
paging (i.e. splitting a large result set into pages), and makes it easy to modify
the data in the underlying data source.
To sum up, GridView controls provide the following functionality:
❑
database table-like presentation
❑
table headers and footers
❑
paging
❑
sorting
428
Chapter 11: Managing Content Using Grid View and Details View