I have a List<Event> and an Event has a Date property. I’m currently binding this list to an asp:repeater which is fine and results in a list of event titles like this:
event 1
event 2
event 3
event 4
event 5
However, now I wish to add some kind of separator to my list between events occurring on different days so that my list looks like:
Tuesday, May 10, 2011
event 1
event 2
Wednesday, May 11, 2011
event 3
Thursday, May 12, 2011
event 4
event 5
Can anyone recommend a good way to do this. I’m happy to manipulate my list server-side or to bind my list and then add the separators client-side with jQuery. Any suggestions?
You can group by date server side using Linq’s GroupBy
GroupByreturnsIEnumerable<IGrouping<TKey, TSource>>, so in this case you are returningIEnumerable<IGrouping<DateTime, Event>>