You need to display a 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.
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 2-13. Examples 2-33, 2-34 through 2-35 show the .aspx and code-behind files for an application that illustrates this approach; the application uses the stored procedure shown in Example 2-32 to retrieve the data to display.
The solution we advocate for the problem of paging through large datasets requires a somewhat different approach to custom paging and managing the labels used to display the current and total pages.
Figure 2-13. Paging through a record-heavy DataGrid output
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
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
PageSize attributes. When ...