| |||||||||||||||||||||||||||
Specifying Paging Behavior in a DataGrid ControlControls You Can Use on Web Forms ASP.NET Data Controls DataGrid Control The DataGrid Web server control enables paging thru data in the grid using any of these methods:
Automatic versus Manual PagingThe page displayed by the grid is determined by its CurrentPageIndex property. The built-in controls set this property automatically; if you are providing custom navigation controls, you set this yourself. After the CurrentPageIndex is set, the grid should be re-bound to the data source. The grid will recreate the entire data set and automatically move to the appropriate place in the data set. It then displays enough rows to make up one page of the grid. If you are working with a large data set, recreating the entire data set each time users navigate to a new page can degrade performance. In this case, you might prefer to get data in page-size "chunks" that is, retrieve just a page worth of records at a time. To do that, you turn off the automatic paging feature of the grid so that it does not assume that it is working with the entire data set. You then manually get the correct number of rows to fill the grid. For details, see Creating Manual Paging below. Using the Built-In Paging ControlsTo use default paging, you set properties to enable paging, set the page size, and specify the style of the paging controls. Paging controls are LinkButton controls. You can choose from these types:
You must also create an event-handling method that responds when users click a navigation control. To use the built-in paging controls
The following code snippet shows the typical logic for the PageIndexChanged event handler.
Providing Custom Navigation ControlsYou can provide your own navigation buttons and manipulate the CurrentPageIndex property of the DataGrid. The DataGrid will still take care of breaking the data source into appropriate pages and displaying the selected page. When you create manual paging, you can use any way you like to set the pager style that the grid should display. To provide custom navigation controls
The below snippet shows how you can create code for a custom navigation panel that allow the user to go to the first, last, previous, or next page. The paging elements are defined as <asp:Button> controls whose CommandArgument property is set to indicate what page they go to. All four buttons call the following method when they are clicked.
By default, the DataGrid control recreates the data set each time the user navigates to a new page and then calculates which rows to display for the requested page. This may not be efficient, however, in applications that need to access large data sets. By using the AllowCustomPaging property of the DataGrid, you can have complete control over which records are displayed. Custom paging improves performance by reducing the amount of data moved around in the system, since you can retrieve just one page of data at a time from the data source. To do so, you turn off automatic paging, then take responsibility in your own code to get just the data for a single page. The following examples demonstrate two different ways of using the AllowCustomPaging property to enable custom paging. One uses an autoincrement data model, and the other uses a data source with primary keys.
|
| ||||||||||||||||||||||||||
Check out related books at Amazon
© 2000-2008 Rey Nuñez All rights reserved.
If you have any question, comment or suggestion
about this site, please send us a note