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. Paging in GridView

Paging in GridView

Scheduled Pinned Locked Moved ASP.NET
databasecssalgorithms
7 Posts 4 Posters 0 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.
  • P Offline
    P Offline
    Pankaj Chamria
    wrote on last edited by
    #1

    Hi, I have a aspx page with a GridView with Paging and Sorting enabled. I opened a SQL Profiler to check at what times the stored procedure which fetches data to bind to GridView is being called. When I go to another page and come back to the GridView page then the procedure does not get called. But when I use the paging feature of the GridView and try to see next 10 records on the second page of GridView, my profiler shows a call to the stored procedure which always returns say 100 rows. If my procedure at the first place did give the GridView all the 100 rows then why upon changing GRid Pages the procedure gets called again. NOTE: I have bound the GridView using SqlDataSource.

    Pankaj Chamria, Software Programmer.

    A N 2 Replies Last reply
    0
    • P Pankaj Chamria

      Hi, I have a aspx page with a GridView with Paging and Sorting enabled. I opened a SQL Profiler to check at what times the stored procedure which fetches data to bind to GridView is being called. When I go to another page and come back to the GridView page then the procedure does not get called. But when I use the paging feature of the GridView and try to see next 10 records on the second page of GridView, my profiler shows a call to the stored procedure which always returns say 100 rows. If my procedure at the first place did give the GridView all the 100 rows then why upon changing GRid Pages the procedure gets called again. NOTE: I have bound the GridView using SqlDataSource.

      Pankaj Chamria, Software Programmer.

      A Offline
      A Offline
      Aavesh Agarwal
      wrote on last edited by
      #2

      U have to use the Gridview_paging Event..in this u have find the currentindex of the Gridview give this index to the newIndex of the Gridview...then bind the Grid again.

      P 1 Reply Last reply
      0
      • A Aavesh Agarwal

        U have to use the Gridview_paging Event..in this u have find the currentindex of the Gridview give this index to the newIndex of the Gridview...then bind the Grid again.

        P Offline
        P Offline
        Pankaj Chamria
        wrote on last edited by
        #3

        But how will this not call the stored procedure again.??

        Pankaj Chamria, Software Programmer.

        A 1 Reply Last reply
        0
        • P Pankaj Chamria

          But how will this not call the stored procedure again.??

          Pankaj Chamria, Software Programmer.

          A Offline
          A Offline
          Ahmad Adnan
          wrote on last edited by
          #4

          u have to creat function that binds the grid ie BindGrid(); call it on load; then creat gridview_pageindexchanging and put in it { gv.PageIndex=e.New index; BindGrid(); }

          1 Reply Last reply
          0
          • P Pankaj Chamria

            Hi, I have a aspx page with a GridView with Paging and Sorting enabled. I opened a SQL Profiler to check at what times the stored procedure which fetches data to bind to GridView is being called. When I go to another page and come back to the GridView page then the procedure does not get called. But when I use the paging feature of the GridView and try to see next 10 records on the second page of GridView, my profiler shows a call to the stored procedure which always returns say 100 rows. If my procedure at the first place did give the GridView all the 100 rows then why upon changing GRid Pages the procedure gets called again. NOTE: I have bound the GridView using SqlDataSource.

            Pankaj Chamria, Software Programmer.

            N Offline
            N Offline
            N a v a n e e t h
            wrote on last edited by
            #5

            Pankaj C wrote:

            If my procedure at the first place did give the GridView all the 100 rows then why upon changing GRid Pages the procedure gets called again.

            You should take a good book and learn how web pages works. HTTP is a stateless protocol. Gridview fetches all the rows when it is binded at the very first time. When you press the next button on pager, entire page will be posted to the server which removes all the values binded on the last page. So it will fetch all those data again and bind it to grid view, Pageindex will be checked then and it moves to the page specified. This will make performance issues when you are working with large set of data's. So I prefer to do custom paging always, by fetching required number of rows from DB. Hope this helps


            My Website | Ask smart questions

            P 1 Reply Last reply
            0
            • N N a v a n e e t h

              Pankaj C wrote:

              If my procedure at the first place did give the GridView all the 100 rows then why upon changing GRid Pages the procedure gets called again.

              You should take a good book and learn how web pages works. HTTP is a stateless protocol. Gridview fetches all the rows when it is binded at the very first time. When you press the next button on pager, entire page will be posted to the server which removes all the values binded on the last page. So it will fetch all those data again and bind it to grid view, Pageindex will be checked then and it moves to the page specified. This will make performance issues when you are working with large set of data's. So I prefer to do custom paging always, by fetching required number of rows from DB. Hope this helps


              My Website | Ask smart questions

              P Offline
              P Offline
              Pankaj Chamria
              wrote on last edited by
              #6

              Tks Navaneeth. Your answer nelped a lot. I will try and implement caching on my collection that binds to the GridView to improve performance. Although I guess custom paging is a much better option for huge no of records.

              Pankaj Chamria, Software Programmer.

              N 1 Reply Last reply
              0
              • P Pankaj Chamria

                Tks Navaneeth. Your answer nelped a lot. I will try and implement caching on my collection that binds to the GridView to improve performance. Although I guess custom paging is a much better option for huge no of records.

                Pankaj Chamria, Software Programmer.

                N Offline
                N Offline
                N a v a n e e t h
                wrote on last edited by
                #7

                Pankaj C wrote:

                Tks Navaneeth. Your answer nelped a lot.

                Welcome.

                Pankaj C wrote:

                I will try and implement caching on my collection that binds to the GridView to improve performance.

                Instead of caching, you could go for custom paging. Caching might show weird results for users browsing site at same time.


                My Website | Ask smart questions

                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