fetching multiple records in Gridview
-
I have 1000 records that i m showing in gridview. i also implemented paging in gridview to show users 5,10,20,50 and all records per page.if user select 10 from drop down then 10 records are showing and when he clicks on next page then i fetched all the records again and show next 10 records. How can i only fetched next 10 records,so that burden on database decreases. Means after 10 records we should fetched 11 to 20 records only. Can anybody provide me code to solve this problem. Any help is greatly appreciated...
-
I have 1000 records that i m showing in gridview. i also implemented paging in gridview to show users 5,10,20,50 and all records per page.if user select 10 from drop down then 10 records are showing and when he clicks on next page then i fetched all the records again and show next 10 records. How can i only fetched next 10 records,so that burden on database decreases. Means after 10 records we should fetched 11 to 20 records only. Can anybody provide me code to solve this problem. Any help is greatly appreciated...
Hi Are you having any identity column (or serial number) field in your application? Then you need to pass extra parameters like current page number and number of records per page to your SP and based on these parameters you can return results. -- Calculate first and last record number
SET @FirstRec = (@CurrentPageIndex - 1) * CAST(@PageSize AS INT) SET @LastRec = (@CurrentPageIndex * CAST(@PageSize AS INT) + 1) SELECT * FROM Table1 WHERE IDCol > @FirstRec AND IDCol < @LastRec
If @PageSize = 10 and @CurrentPageIndex = 1, then @FirstRec will be 0 and @LastRec = 11. So first page will return only 10 records If @PageSize = 20 and @CurrentPageIndex = 1, then @FirstRec will be 0 and @LastRec = 21. So first page will return only 20 records and so on. Hope this solves your problems.Harini
-
I have 1000 records that i m showing in gridview. i also implemented paging in gridview to show users 5,10,20,50 and all records per page.if user select 10 from drop down then 10 records are showing and when he clicks on next page then i fetched all the records again and show next 10 records. How can i only fetched next 10 records,so that burden on database decreases. Means after 10 records we should fetched 11 to 20 records only. Can anybody provide me code to solve this problem. Any help is greatly appreciated...
best way to use Cache.
Best Regards ----------------- Abhijit Jana Microsoft Certified Professional "Success is Journey it's not a destination"
-
Hi Are you having any identity column (or serial number) field in your application? Then you need to pass extra parameters like current page number and number of records per page to your SP and based on these parameters you can return results. -- Calculate first and last record number
SET @FirstRec = (@CurrentPageIndex - 1) * CAST(@PageSize AS INT) SET @LastRec = (@CurrentPageIndex * CAST(@PageSize AS INT) + 1) SELECT * FROM Table1 WHERE IDCol > @FirstRec AND IDCol < @LastRec
If @PageSize = 10 and @CurrentPageIndex = 1, then @FirstRec will be 0 and @LastRec = 11. So first page will return only 10 records If @PageSize = 20 and @CurrentPageIndex = 1, then @FirstRec will be 0 and @LastRec = 21. So first page will return only 20 records and so on. Hope this solves your problems.Harini
Thank u sir
-
Hi Are you having any identity column (or serial number) field in your application? Then you need to pass extra parameters like current page number and number of records per page to your SP and based on these parameters you can return results. -- Calculate first and last record number
SET @FirstRec = (@CurrentPageIndex - 1) * CAST(@PageSize AS INT) SET @LastRec = (@CurrentPageIndex * CAST(@PageSize AS INT) + 1) SELECT * FROM Table1 WHERE IDCol > @FirstRec AND IDCol < @LastRec
If @PageSize = 10 and @CurrentPageIndex = 1, then @FirstRec will be 0 and @LastRec = 11. So first page will return only 10 records If @PageSize = 20 and @CurrentPageIndex = 1, then @FirstRec will be 0 and @LastRec = 21. So first page will return only 20 records and so on. Hope this solves your problems.Harini
Hi Friend, I can't get the logic,can you explain again.Please.....