In this chapter, we examined the grid controls available in ASP.NET DataGrid and the newer GridView. Grids are a type of component that all Web applications need to employ in one shape or another. All Web applications, in fact, at a certain point of their life cycles are called to display data. More often than not, this data is in tabular format.
As long as the data to be displayed can be articulated in rows and columns, a grid is ideal for displaying it. Such controls provides facilities to select and edit single rows, page through a bound data source, and sort views. In addition, you can customize all the cells in a column by using any data-bound template made of any combination of HTML and ASP.NET text. To top it off, a fair number of events signal to user applications the key events in the control's life cycle.
The in-place editing feature is a piece of cake to use, as it is powerful and easy to configure. Even though this type of editing designed to resemble Excel worksheets is not appropriate for all applications and pages, as long as you can functionally afford the feature, in-place editing can save you a lot of coding and increase productivity by at least one order of magnitude.
Why are there two grid controls in ASP.NET 2.0? Let's state the answer clearly the DataGrid control is supported mostly for backward compatibility. If you're writing a new ASP.NET 2.0 application, choosing to use the GridView is a no-brainer. The GridView has a newer and more effective design and totally embraces the data-binding model of ASP.NET 2.0. The key shortcoming of ASP.NET 1.x data binding is that it requires too much code for common, relatively boilerplate operations. This has been addressed with the introduction of data source controls. But data source controls require richer data-bound controls that are capable of working with the new model. This explains why ASP.NET 2.0 offers a brand-new control the GridView rather than just enhancing the existing DataGrid.
In the next chapter, we'll cover a pair of controls named DetailsView and FormView the perfect complements to the GridView. These two controls fill another hole in the ASP.NET 1.x data toolbox, as they offer a smart interface for displaying individual records.