1.9. Adding Direct Page Navigation to a DataGrid
Problem
You need to display data in a table, but the database that stores it has more rows than can fit on a single page, and you want to allow the user to select the page to display.
Solution
The simplest solution is to use a DataGrid control
and its PagerStyle-Mode and
PagerStyle-PageButton attributes to enable page
selection. This approach produces output like that shown in Figure 1-9. To create an application that employs this
approach, start by implementing Recipe 1.7 with the changes to the
DataGrid tag shown here:
PagerStyle-Mode="NumericPages" PagerStyle-PageButtonCount="5"

Figure 1-9. Output of simple solution to DataGrid direct paging
A more flexible solution is to hide the pager provided by the
DataGrid control and implement your own user
interface for the pagination controls. This approach allows the user
to, for example, input a page number in a text box and then click a
button to display the data, as shown in Figure 1-10.
Example 1-23 through Example 1-25 show the .aspx and
code-behind files for an application that produces this result.

Figure 1-10. Custom direct page navigation with a DataGrid output
Discussion
In the simple solution, setting the
PagerStyle-Mode attribute to
NumericPages causes the
DataGrid to be rendered with ...
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