In ASP.net when we perform paging over Gridview or DetailsView than the Gridview fetch all rows from the Database each time.
Suppose our Database contains 100 rows and we have configured Paging in Gridview with page size of 10 records per page.But whenever we click on the the pager control of gridview for any particular page no. then GridView should fetch only particular 10 rows from database.
If we click on page no 3 then it should query only rows 21-30 but it fetches all rows and neglect the remaining .which is simply a wastage of resources.
Can any one of please suggest me a solution to this problem?
You can store the record index in viewstate or in hidden fields run at = server. So, while you first load, set the pageindex to 0 and say you display 20 records. When the next is clicked, update the page index (pageindex++). Say when you click 8th page, set the page index to 8 and so on.
From the Add New Item window, select ADO.NET Entity Data Model and set its Name as NorthwindModel and then click Add. Then the Entity Data Model Wizard will open up where you need to select EF Designer database option. Now the wizard will ask you to connect and configure the Connection String to the database.
To implement this optimized data fetch, you have to implement custom paging (rather than using the GridView paging). Also, you should use SQL to get only the rows that you want to show on a page (not all of the data).
See the following related links:
Custom Paging in Asp.net
Paging tons of data in GridView
How to get Specific rows From Table by Id Range
Paging Large Datasets in SQL Server
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With