Paging in GridView
-
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.
-
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.
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.
-
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.
But how will this not call the stored procedure again.??
Pankaj Chamria, Software Programmer.
-
But how will this not call the stored procedure again.??
Pankaj Chamria, Software Programmer.
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(); }
-
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.
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
-
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
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.
-
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.
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.