I am in the situation of working with large amount of records in a grid. Instead of, binding all records into the grid. why we should not bind set of records which are belongs to 5th page.
- 3There are many, many examples of paging for grids on the internet. Perhaps a search on a famous search engine will lead you in the right direction.Lazarus– Lazarus2009-06-23 13:36:28 +00:00Commented Jun 23, 2009 at 13:36
- If you tell us more precisely what you are looking for (code, theory, etc.) we may be able to give you some answers.Joel– Joel2009-06-23 13:38:35 +00:00Commented Jun 23, 2009 at 13:38
- Sadly, may examples I've seen of paging put an entire DataSet into ViewState. Keep looking if yuo see that - there are some clever stored-proc ideas that take page#/sort-col info as arguments.n8wrl– n8wrl2009-06-23 13:49:45 +00:00Commented Jun 23, 2009 at 13:49
- your solution to this problem worked out well in my case. thank youFairy_G– Fairy_G2009-10-01 06:22:40 +00:00Commented Oct 1, 2009 at 6:22
2 Answers
You can enable paging on your GridView by setting AllowPaging to true and PageSize to the number of records you wish to display per page.
The advantage of paging is that you can bind the full data source to your GridView and allow the user to move between pages, it's much less programming on the server side to always work with the full data source.
EDIT:
It is also recommended that you don't put the entire dataset in the GridView view state, a better option would be to cache the data and rebind in the Page Load
1 Comment
As a good practice one should not bind all the records retrieved from a query directly to a control such as grid view , unless of course you are absolutely sure that the number of records are few.
This is because when the number of records are huge, the page loads slower,since binding takes a lot of time.
One approach that I have used in my previous project is to fetch the total number of records affected by the query. (Lets say they are 1000).
I then divide the number of records with the page size (say 100).
So now I provide pagination with pages (1-10).
When the user clicks on a particular page, I fetch records pertaining to that page using ROW_NUMBER() function in SQL.
The query will be something like
SELECT x, y, ROW_NUMBER() OVER(ORDER BY z asc) AS 'RowNumber' FROM t WHERE RowNumber > lowerlimit and RowNumber < upperlimit. Lowerlimit and upperlimit are calculated using the current page number and page size.
I hope this answers your question