When it comes to displaying tabular data, ASP.NET can save you a lot of time, provided you play your cards right. If you want to display data from a database in a table and you're not concerned about performance or your ability to control the arrangement of the data items within the display, you can whip up something with the GridView control in minutes using a few lines of code. Alternatively, if you're more inclined to control the tabular display, you can shape and mold the template-driven Repeater and DataList controls beyond recognition and still not step far outside a well-trodden path. But like everything else in ASP.NET, you have to know where to start and what the trade-offs are. For instance, it's helpful to know how and when the GridView control begins to fall short of the mark. That knowledge will save you the trouble of having to retrace your steps later to implement another tabular control altogether, something we've had to do ourselves at an inopportune moment during a hot project. The recipes in this chapter ought to get you well down the curve with displaying your tabular data and prevent you having to revisit some of our same mistakes.
For readers of the first edition of the ASP.NET Cookbook, you should know that we have revised this chapter to incorporate the latest enhancements to ASP.NET 2.0, including, for example, updating all the code to leverage the latest techniques as well as adding several strategies for taking best advantage of the new GridView control.
While on the subject of the GridView control, you might also have the impression that the new GridView control is the all-in-one solution for displaying tabular data. We do not hold with this view; for one thing, the server processing required to build the applicable output is large and may not always be the best approach for your application. What's more, the GridView does not afford the flexibility that its predecessors, particularly the DataGrid, offer in terms of controlling custom paging. The GridView is a useful new control. But, lest you apply GridView too broadly to your code, it helps to know its strengths and limitations as we will lay out in the chapter's first recipe.