开发者

Asp.net listview paging without havind all records in memory

In my asp.net page I have a listview that has a datapager defined in the LayoutTemplate. The listview is databound to a list of records. I know the total number of records ... but I don't load them from the db. I want to tell the pager at first request the total number of records and let it generate the pages an开发者_开发问答d navigation. When the user click a page from the datapager I want to load the records from the db and update the listview binding to display results from that page.

Is this possible with the listview and datapager from asp.net?

Thanks, Radu


You can maintain the pager separately from the listview. The SetPageProperties method of DataPager will be useful to you here. Then, you can set the datasource of your listview to the appropriate 'page' of DB records during OnDataBinding or Page_Prerender (depending on how you want to deal with postback events).


It is not possible using just these controls. However, you can write custom code in the event handlers of these controls to do what you want.

In my experience, the best way to do this is via a stored proc on the db side that takes a startIndex parameter and a pageSize parameter and returns only the results that you want. (Of course the parameters can be different that what I wrote, but you get the idea)


After more research I found this article that describe how to cache data and use it with the ObjectDataSource. Probably you know all this ... but I am new with asp.net.

Caching data in Asp.net

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜