Splitting a list by Date property in C # or using jQuery

I have List<Event>, but Eventhas a property Date. Currently, I bind this list to asp:repeater, which is good, and leads to a list of event names like this:

event 1
event 2
event 3
event 4
event 5

However, now I want to add some sort of separator to my list between events occurring on different days, so that my list looks like this:

Tuesday, May 10, 2011
event 1
event 2
Wednesday, May 11, 2011
event 3
Thursday, May 12, 2011
event 4
event 5

- . , jQuery. ?

+3
4

Linq GroupBy

class Event
{
    public DateTime EventDate;
    public string EventName;
}

List<Event> events = GetEvents();

var grouped = events.GroupBy(e => e.EventDate.Date).OrderBy(g => g.Key);

foreach (var grouping in grouped)
{
    Console.WriteLine(grouping.Key); // <-- this is the date

    foreach (Event e in grouping) // <-- this is the list of events
    {
        Console.WriteLine(e.EventName); 
    }
}

GroupBy IEnumerable<IGrouping<TKey, TSource>>, IEnumerable<IGrouping<DateTime, Event>>

+2

- .

.

Repeaters -, , Repeater.ItemDataBound.

+1

.

0

:

List date = (From Event n in yourEventList
                      select new {n.Date}).ToList().Distinct();

foreach (DateTime dateA in date)
{
// add to the Date and then add the events does match with the date.
}
0
source

All Articles