Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. fetching multiple records in Gridview

fetching multiple records in Gridview

Scheduled Pinned Locked Moved ASP.NET
helpdatabasequestion
5 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kartik Rathi
    wrote on last edited by
    #1

    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...

    H A 2 Replies Last reply
    0
    • K Kartik Rathi

      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...

      H Offline
      H Offline
      Harini N K
      wrote on last edited by
      #2

      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

      K S 2 Replies Last reply
      0
      • K Kartik Rathi

        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...

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        best way to use Cache.

        Best Regards ----------------- Abhijit Jana Microsoft Certified Professional "Success is Journey it's not a destination"

        1 Reply Last reply
        0
        • H Harini N K

          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

          K Offline
          K Offline
          Kartik Rathi
          wrote on last edited by
          #4

          Thank u sir

          1 Reply Last reply
          0
          • H Harini N K

            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

            S Offline
            S Offline
            senthilsstil
            wrote on last edited by
            #5

            Hi Friend, I can't get the logic,can you explain again.Please.....

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups