Radu D
Radu D

Reputation: 3555

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 and 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

Upvotes: 1

Views: 968

Answers (3)

Radu D
Radu D

Reputation: 3555

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

Upvotes: 0

Dan Davies Brackett
Dan Davies Brackett

Reputation: 10071

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).

Upvotes: 2

light
light

Reputation: 816

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)

Upvotes: 0

Related Questions