2.1. Selecting the Right Tabular Control
Problem
You want to use an ASP.NET control to display some data in a tabular format.
Solution
Use a Repeater, DataList, DataGrid
, or GridView
control. Always choose the smallest and fastest control that meets your needs, which invariably will be influenced by other criteria as in these examples:
- If you need a quick and easy solution
Use a
GridView
.- If you need a lightweight read-only tabular display
Use a
Repeater
.- If you need your solution to be small and fast
Use a
Repeater
(lightest) orDataList
(lighter).- If you want to use a template to customize the appearance of the display
Choose a
Repeater
orDataList
.- If you want to select rows or edit the contents of a data table
Choose a
DataList
, aDataGrid
, or aGridView
.- If you want built-in support to sort your data by column or paginate its display
Choose a
GridView
.- If you want to use custom pagination
Choose a
DataGrid
.
Discussion
ASP.NET provides four excellent options for displaying tabular data: Repeater, DataList, DataGrid
, and GridView
. Each comes with trade-offs. For instance, the GridView
control is versatile, but you can pay a price in terms of performance. On the flip side, the Repeater
control is lighter weight but is for read-only display; if you later decide you need to edit your data, you will have to rework your code to use the DataList, DataGrid
, or GridView
control instead (unless, of course, you want to embark on your own custom coding odyssey).
The impact on performance is because ASP.NET ...
Get ASP.NET 2.0 Cookbook, 2nd 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.