views:

642

answers:

2

I have a ListView that I am databinding to a collection of objects something like this:

int total;
List<Client> clientList = 
    clientData.GetClients(criteria, pageNum, pageSize, out total);
uxClientList.DataSource = clientList;
uxClientList.DataBind();

Where the pageNum, pageSize and total parameters facilitate paging at the data access layer. So far so good.

Now I can throw a DataPager on the page, point it at the ListView and get a decent paging UX. There's a little more to it when you're binding programmatically instead of declaratively with a data source control, but the problem here is that DataPager expects that the entire result set is being retrieved each time, from which it should calculate pagination, so it sees the single page of results returned as the total available records and gets rendered as if there is only one page of results available. In other words, the above scenario works fine with DataPager if we switch to a non-paging version of GetClients:

List<Client> clientList = clientData.GetClients(criteria);
uxClientList.DataSource = clientList;
uxClientList.DataBind();

Obviously since our data access layer is kind enough to provide us with a method to retrieve a page at a time, this would be preferable to retrieving all records every time. It would be nice if we could explicitly inform DataPager of the total available records so it could still automatically create pagination output, but only require one page at a time to do so.

I haven't found an easy way to do this and I haven't turned up anything in searches. Admittedly I don't currently posses a deep understanding of the implementation of DataPager, so hopefully I'm overlooking something.

+1  A: 

You haven't overlooked anything.

When dealing with large result sets you need to turn paging off and add your own paging controls.

In my experience << < > >> suffice. Nobody goes past the 3rd page anyway.

Seth Reno
Well said... I do like numeric paging a la Stackoverflow though :-)That said I did whip up a really simple numeric pager... I just like some of the bells and whistles of DataPager. All well.
I Have the Hat
i knocked up a stackoverflow style datapager, will post the code if youre interested (it doesn't do server paging though)
flesh
Would love to see the code for the Stackoverflow style pager
codemypantsoff
+1  A: 

Have a look at the ListViewPagedDataSource and its AllowServerPaging property, I think that may be what you're looking for..

flesh
Very interesting... the sparse documentation on said property would seem to suggest that. I will play with it as soon as I have time.
I Have the Hat