views:

33

answers:

2

In ASP.NET Can we achieve both grouping and sorting in a repeater control. If possible please suggest me the way of doing it or links .. I have to implement that in my application

Thank You.

+1  A: 

If you mean visual grouping, the way I have done this sort of thing in the past is to add an ItemDataBound event to the repeater which checks the previous item using MyRepeater.Items[e.Item.ItemIndex-1]. If I've determined that a new group has started (i.e., if the previous item started with a different letter than the current item, and I am sorting alphabetically and grouping by letter) then I inject the appropriate HTML markup into a Literal control in the ItemTemplate to create the visual groupings.

Rudism
+1  A: 

Couldn't you use the ListView control instead of a repeater? This has built in support for sorting and a kind of grouping whilst still offering the layout flexibility you get with a Repeater.

Dan Diplo