1.3. Enhancing the Output of a Tabular Display
Problem
You need to display data from
a
database in a way that lets you organize and enhance the output
beyond the confines of the DataGrid
control’s default tabular display. Selecting and
editing the data are not important, nor is navigating through the
data.
Solution
Use a Repeater control with
templates and then bind the data
to the control.
In the .aspx file, add a
Repeater control and the associated templates for
displaying the data.
In the code-behind class for the page, use the .NET language of your choice to:
Open a connection to the database.
Build a query string, and read the desired data from the database using an
OleDbCommandandOleDbDataReader.Assign the data source to the
Repeatercontrol and bind it.
Figure 1-2 shows the appearance of a typical
Repeater in a browser. Example 1-4 through Example 1-6 show the
.aspx and code-behind files for an application
that produces this result.

Figure 1-2. Using templates with Repeater control display output
Discussion
When your primary aim is to organize and enhance the output beyond
the confines of the DataGrid
control’s default tabular display, the
Repeater control is a good choice because, unlike
a DataGrid, it has associated templates that allow you to use virtually any HTML to format the displayed data. It also has the advantage of being relatively lightweight and easy to use. When using ...
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