GridView Control
Now that you have a working data source control on your web page, let’s hook it up to a control to display the data you’ve retrieved. You will use a GridView
control, the workhorse data grid in ASP.NET.
The GridView
is derived from the BaseDataBoundControl
class, along with many other controls, such as the AdRotator
, DetailsView
, and FormView
controls, the members of the ListControl
class, such as CheckBoxList
, RadioButtonList
, and so on, and composite controls, such as the password controls, wizards, and so on. The DataGrid
and DataList
controls derive from BaseDataList
, not BaseDataBoundControl
. (Refer to Figure 3-3 in Chapter 3 for a schematic diagram of the class structure of System.Web.UI.Control
.) Though they derive from different base classes, the GridView
and the DataList
(described later in this chapter) share many of the same properties.
Tip
Users of ASP.NET Version 1.x, will probably now use a GridView
rather than a DataGrid
control. GridView
does all that the DataGrid
does and much more, including providing easier paging and sorting. The DataGrid
is fully compatible with Version 2.0, with no requirement to modify existing projects to run under the new version.
Many of the most commonly used properties of the GridView
control not inherited from the control or WebControl
classes are listed in Table 9-1. Many of these properties are described and used in subsequent sections of this chapter.
Table 9-1. GridView properties not inherited from WebControl
Property ... |
---|
Get Programming ASP.NET, 3rd Edition 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.