Paging in DataGrid
The DataGrid provides the means to display a group of records from the data source (for example, the
first 10), and then navigate to the "page" containing the next 10 records, and so on through the data.
You enable paging in DataGrid by setting AllowPaging to true. When enabled, the grid will display page
navigation buttons either as "next/previous" buttons or as numeric buttons. When a page navigation button is clicked, the PageIndexChanged event is thrown. It's up to you to handle this event in your code. The most basic logic assigns the CurrentPageIndex to the event argument's NewPageIndex property and then rebinds the data source, as shown in the following example.
The DataGrid has a built-in page navigation control, called the "pager," which displays either as "next/previous"
buttons or as a set of numeric page buttons. You can hide the built-in pager user interface and supply your own paging UI.
To change the page, you must set the CurrentPageIndex to the desired page (base 0), and rebind the
data source to the grid.
For very large data models, it is expensive to load the entire data source each time the grid is paged. A
common alternative is to retrieve the data in page-size chunks, rather than retrieving all of
the data and then stepping into the current row.
The DataGrid supports chunking through the AllowCustomPaging and VirtualItemCount properties. If
AllowCustomPaging is true, the DataGrid does not calculate a starting display position in the data model based
on CurrentPageIndex. Instead, DataGrid displays all of the data in the data model, while its pager
reports the current position as page CurrentPageIndex of (VirtualItemCount+PageSize-1)/PageSize. The following example demonstrates this functionality.
Copyright 2001 Microsoft Corporation. All rights reserved.