Paging Mechanism

大城市里の小女人 提交于 2019-12-13 03:26:14

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/1032596/paging-mechanism

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!