1.10. Paging Through a Record-Heavy DataGrid
Problem
You need to display a very large
set of data in a
DataGrid, yet the user must be able to page
through it quickly. This approach is beneficial anytime you have to
navigate through thousands of records.
Solution
Use custom paging with a DataGrid and, using a
stored procedure, read from the database only the data that is needed
for a given page. An example of the output that can be achieved with
this approach is shown in Figure 1-11. Examples
Example 1-27 through Example 1-29
show the .aspx and code-behind files for an
application that illustrates this approach; the application uses the
stored procedure shown in Example 1-26 to retrieve
the data to display.

Figure 1-11. Paging through a record-heavy DataGrid output
Discussion
The solution we advocate for the problem of paging through large datasets requires a somewhat different approach to both custom paging and managing the labels used to display the current and total pages.
To enable paging and to allow you to control movement within the
dataset when data binding, the
DataGrid’s
AllowPaging and
AllowCustomPaging attributes
must be set to
True. When AllowCustomPaging is
set to False (the default), the
DataGrid assumes that all of the data that can be
displayed in all pages is present in the data source, and it
calculates the group of records to display from the
CurrentPageIndex and ...
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