1.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, or
DataGrid control. Always
choose
the smallest and fastest control that meets your needs, which
invariably will be influenced by other criteria. For example:
- If you need a quick and easy solution
Use a
DataGrid.- 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
RepeaterorDataList.- If you want to select rows or edit the contents of a data table
Choose a
DataListor aDataGrid.- If you want built-in support to sort your data by column or paginate its display
Choose a
DataGrid.
Discussion
ASP.NET provides three excellent options for displaying tabular
data—Repeater, DataList,
and DataGrid—but each comes with trade-offs.
For instance, the DataGrid control is particularly
versatile, but you can pay a heavy 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 must rework your code to use the
DataList or DataGrid control
instead (unless, of course, you want to embark on your own custom
coding odyssey).
The impact on performance is due to the fact that ASP.NET creates an
actual control for every element of a DataGrid control, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access