by Arra Derderian
6. November 2010 23:25
I have always utilized the repeater control when I need a flexible lightweight data binding control. Based on some of the new functionality in .NET 4.0 I may be switching to the ListView control.
In .NET 4.0 the ListView control has a property called ClientIDRowSuffix where you can specify it to automatically generate unique ID's for elements that are dynamically created by the ListView. This is great because using AJAX to update rows or load new rows you need a unique identifier for each element and you would always have to build this logic in on your own. Microsoft also built in the ability to have .NET generate client ID's that are closer to what you actually specify than the automatically generated ID's of previous versions. You should specify ClientIDRowSuffix="ID" and ClientIDMode="Predictable" to get this to work. You will then be given ID's on your elements that are uniquely based on the ID property of your datasource and the ListView ID + Control ID.
These new features are great for client side manipulation and allow you to target elements easily by ID using a library like jQuery. Having to target elements by class is slower and also mixes logic with presentation.
Also, the ListView control allows a lot more templates to be defined for scenarios such as EmptyItems, SelectedItems, and InsertingItems. Support for grouping, sorting, and pagination is very good as well. I especially like that instead of declaring header, item, and footer templates you declare a layout template that specifies how to render the surrounding markup of the items. This lets you not have broken table or list structures in your code that produce warnings.
I think it might be time to give up the old repeater and move on.