How does gridview paging work




















To determine the total number of pages required to display the data source contents, use the PageCount property. You can determine the index of the currently displayed page by using the PageIndex property. When paging is enabled, an additional row called the pager row is automatically displayed in the 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 PagerSettings property.

The pager row can be displayed at the top, bottom, or both the top and bottom of the control by setting the Position property. You can also select from one of four built-in pager display modes by setting the Mode property. The following table describes the built-in display modes. To control the appearance of the pager row including its background color, font color, and position , use the PagerStyle property.

The GridView control automatically hides the pager row when the data source contains only one page of records. The 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 PagerTemplate. The GridView control provides several events that you can use to perform a custom action when paging occurs. The following table lists the available events. Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services.

Now using the custom paging logic the GridView is loaded with only the data you needed. After getting the conceptual knowledge, let's start coding to use GridView paging with custom paging logic in ASP.

Set the "VirtualItemCount" property of the GridView with the total number of records in the database. And bind the datasource with PageSize 10 and PageIndex value 0 as this is first page to show. After that we need to write code in the PageIndexChanging event of the GridView and bind the grid with the current page. Here, I also create two Stored Procedures in SQL Server; one to fetch the total records count and another to fetch the data corresponding to the current page index.

Here is the entire code of the application. ASPX markup code. In the code above, I used PagerSetting mode to display the paging. As you can see in the code above, I fetched the total records count and set it to the "VirtualItemCount" attribute of GridView at page load time and load the GridView with starting page index. After that I am fetching what I need for the current page and not binding the entire table to the GridView. Now, it will fetch the records easily when the page index is changed with only the required data that is needed without loading the complete table everytime.

View All. Gaurav Gupta Updated date Jan 28, Regarding this property two points are to be remembered: You have more records count than the value of PageSize you will set. Open an ASP. NET application in the Visual Studio Code of ASPX page. The following mark to set GridView control.

I have given the procedure to help you accomplish it, follow it:. It contains the count of all the records in all the pages of the GridView. It is used by millions of people around the world to learn and explore about ASP.

Enter your email address to subscribe to this blog and receive notifications of new posts by email. YogiHosting » ASP. Search for:. We are helping millions of Beginners and Professionals to learn new programming technologies.

Please consider donating us:. How to easily implement ASP. DataBind ;. NewPageIndex; Search e.



0コメント

  • 1000 / 1000