asp.net.ph

DataGrid.AllowCustomPaging Property

System.Web.UI.WebControls Namespace   DataGrid Class


Sets or retrieves a value specifying whether custom paging is enabled.

Syntax


Inline <asp:datagrid allowcustompaging = true | false ... >
Script DataGrid.AllowCustomPaging [ = true | false ]

Property Value

This property accepts or returns only a boolean value: true if custom paging is enabled; otherwise, false. Default value is false.

Remarks

Paging allows you to display the contents of the DataGrid control in page segments. The number of items on a page is determined by the PageSize property. If no value is specified for the PageSize property, the DataGrid will display 10 items on a page.

Normally, a data source that contains every row in the DataGrid control is loaded every time the DataGrid control moves to a different page. This can consume a lot of resources when the data source is very large. Custom paging allows you to load just the segment of data needed to display a single page.

To enable custom paging, set both the AllowPaging and AllowCustomPaging properties to true. Next, provide code to handle the PageIndexChanged event.

The typical logic for the PageIndexChanged event handler is to first set the CurrentPageIndex property to the index of the page you want to display.

NOTE: The event handler receives a DataGridPageChangedEventArgs object as a parameter. You can use the NewPageIndex property of this parameter to determine the index of the page selected by the user from the page selection elements of the DataGrid control.

Next, create a data source that contains the data to display on a single page and then use the DataBind method to bind the data to the DataGrid control.

NOTE: Because only a segment of the data is loaded, you must set the VirtualItemCount property to the total number of items in the DataGrid control. This allows the control to determine the total number of pages needed to display every item in the DataGrid control. This property is normally programmatically set once the total number of items in the DataGrid control is determined.

When paging is enabled with the AllowCustomPaging property is set to false, the DataGrid control assumes that the data source contains all the items to be displayed. The DataGrid control calculates the indexes of the items on the displayed page based on the page index, specified by the CurrentPageIndex property, and the number of items on a page, specified by the PageSize property.

When the AllowCustomPaging property property is set to true, the DataGrid control assumes that the data source only contains the items as determined by the VirtualItemCount property. All items up to the number of items specified by the PageSize property are displayed.

Example

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.

Custom Paging with AutoIncrement Data Model
Run Sample | View Source
Custom Paging Using Primary Key Values
Run Sample | View Source
See Also

DataGrid Members   VirtualItemCount   CurrentPageIndex   PageSize Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph