Reputation: 2177
If I need pagination support, should I use a ListView or a Repeater ?
I can use a DataPager control with a ListView, but not with a Repeater.
So what would be the best option ? and why ?
Upvotes: 1
Views: 1397
Reputation: 22220
I haven't compared performance of the various data visualization controls since the .NET 1.1 days. But if you are planning on using one of these controls on a very large set of data, then it's something to look out for.
Repeaters have the simplest, most stripped-down functionality and won't add anything to your markup that you don't specifically tell it to. And if you feed it a datareader as its datasource then that can be the most performant combination possible (albeit the most devoid of features).
I guess that doesn't answer your question exactly, but raises more questions.
But... is it worth the effort to create custom paging, or use built-in functionality of a listview/datapager combination? At times, I think it is worth it to go custom.
One thing to worry about is that the DataPager control uses postbacks when navigating between pages.
IMO, postbacks are a crappy way to handle paging. Here's why:
1.) The user can't navigate between pages with the back & forward buttons in their browser history without getting the annoying message about resubmitting your form data.
2.) Search engines can't index each page of results individually because they all use the same URL.
At least with a custom solution you could resolve all of that by using querystrings for each page.
I talk about some of these same issues in my answer to this question.
Upvotes: 3
Reputation: 11858
ListView was designed as the .Net 3.5 replacement for Repeater. If you're writing new code, use ListView.
The Apress Pro ASP.Net in C# book touches on this a little.
Upvotes: 0
Reputation: 21357
You could use either the ListView or Repeater with success - I think the important question is how are you going to implement the paging? How many total records of information is in your source?
It would be super easy to slap the DataPager onto a ListView, set a couple properties and have paging... with the catch that each page actually queries all of your records, most of which get thrown out by the DataPager. This is probably fine in a lot of scenarios, but if you have a lot of records it may not be suitable.
The DataPager does support custom paging (see this), where you do the dirty work on your own (setting up your SQL statements/sprocs to actually only return a "page" of results at a time), but it's some work . At that point, using this with a Repeater isn't much more complicated other than the fact you'll have to render/compute your own paging controls/links on the repeater.
The PagedDataSource I'm less familiar with, but I don't believe you can implement custom paging, so it's probably like the default DataPager (only it could be used with a DataReader too).
So to conclude, either the ListView or Repeater will work, and quite similarly. ListView w/ default DataPager will be comparable to Repeater w/ PagedDataSource, and ListView w/ custom-paged DataPager will be comparable to a Repeater with rolling your own paging code.
Upvotes: 1
Reputation: 3371
I think this article has a great comparison of the two...
http://www.singingeels.com/Articles/The_ListView_Dominates_The_Repeater.aspx
And here is a paging article for the ListView...
http://www.codedigest.com/Articles/ASPNET/100_Paging_in_ListView_in_ASPNet_35.aspx
Upvotes: 1
Reputation: 125488
You can also get pagination in a Repeater using a PagedDataSource
Upvotes: 1
Reputation: 2155
imho ListView is in general better, because you can customize it a lot better.
Upvotes: 1