Documentation for this section has not yet been entered.
Instead of displaying all the records in the data source at the same time, the System.Web.UI.WebControls.GridView control can automatically break the records up into pages. If the data source supports the paging capability, the System.Web.UI.WebControls.GridView control can take advantage of that and provide built-in paging functionality. The paging feature can be used with any data source object that supports the ICollection interface or a data source that supports paging capability.
To enable the paging feature, set the GridView.AllowPaging property to true. By default, the System.Web.UI.WebControls.GridView control displays 10 records on a page at a time. You can change the number of records displayed on a page by setting the GridView.PageSize property. To determine the total number of pages required to display the data source contents, use the GridView.PageCount property. You can determine the index of the currently displayed page by using the GridView.PageIndex property.
When paging is enabled, an additional row called the pager row is automatically displayed in the System.Web.UI.WebControls.GridView control. The pager row contains controls that allow the user to navigate to the other pages. You can control the settings of the pager row (such as the pager display mode, the number of page links to display at a time, and the pager control's text labels) by using the GridView.PagerSettings property. The pager row can be displayed at the top, bottom, or both the top and bottom of the control by setting the PagerSettings.Position property. You can also select from one of four built-in pager display modes by setting the PagerSettings.Mode property. The following table describes the built-in display modes.
PagerButton.NextPrevious |
A set of pagination controls consisting of previous and next buttons. |
PagerButton.NextPreviousFirstLast |
A set of pagination controls consisting of previous, next, first, and last buttons. |
PagerButton.Numeric |
A set of pagination controls consisting of numbered link buttons to access pages directly. This is the default mode. |
PagerButton.NumericFirstLast |
A set of pagination controls consisting of numbered and first and last link buttons. |
To control the appearance of the pager row (including its background color, font color, and position), use the GridView.PagerStyle property.
The System.Web.UI.WebControls.GridView control automatically hides the pager row when the data source contains only one page of records.
The System.Web.UI.WebControls.GridView control also enables you to define a custom template for the pager row. For more information about creating a custom pager row template, see GridView.PagerTemplate.
The System.Web.UI.WebControls.GridView control provides several events that you can use to perform a custom action when paging occurs. The following table lists the available events.
GridView.PageIndexChanged |
Occurs when one of the pager buttons is clicked, but after the System.Web.UI.WebControls.GridView control handles the paging operation. This event is commonly used when you need to perform a task after the user navigates to a different page in the control. |
GridView.PageIndexChanging |
Occurs when one of the pager buttons is clicked, but before the System.Web.UI.WebControls.GridView control handles the paging operation. This event is often used to cancel the paging operation. |