I am in the situation of working with large amount of records in a grid. Instead of, binding all records into the gird. why we should not bind set of records which are belongs to 5th page.
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
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
Hi Prashanth your solution to this problem worked out well in my case. thank you