-
Group a datalist?
Hi all,
I have a datalist which displays the following data from a SQL DB in descending order by date (see example of how data looks in datalist):
Code:
Event Name: Event1
Event Location: 123 Main Street, Milwaukee, WI 58745
Date: 3/17/2009
Time: 5:00 PM - 7:00 PM
Event Name: Event2
Event Location: 456 Main Street, Milwaukee, WI 57674
Date: 2/15/2009
Time: 5:00 PM - 7:00 PM
Event Name: Event3
Event Location: 789 Main Street, Milwaukee, WI 58746
Date: 2/05/2009
Time: 5:00 PM - 7:00 PM
Event Name: Event4
Event Location: 789 Main Street, Milwaukee, WI 58746
Date: 1/06/2009
Time: 5:00 PM - 7:00 PM
Note: These fields are in the item template
This works great except that I'd like to somehow group them by month so it looks something like:
Code:
March 2009
Event Name: Event1
Event Location: 123 Main Street, Milwaukee, WI 58745
Date: 3/17/2009
Time: 5:00 PM - 7:00 PM
February 2009
Event Name: Event2
Event Location: 456 Main Street, Milwaukee, WI 57674
Date: 2/15/2009
Time: 5:00 PM - 7:00 PM
Event Name: Event3
Event Location: 789 Main Street, Milwaukee, WI 58746
Date: 2/05/2009
Time: 5:00 PM - 7:00 PM
January 2009
Event Name: Event4
Event Location: 789 Main Street, Milwaukee, WI 58746
Date: 1/06/2009
Time: 5:00 PM - 7:00 PM
If I throw another label in there with the month information, it will display of course, but it will display for every record. I'd like it to only show once per month. Is there some way I can accomplish this? I'm using VS 2008 and ASP.NET 2.0
Thanks,
Strick
-
Re: Group a datalist?
Could you nest the datalists?
Here's an example using repeaters. I used something similar for a newsletter archive.
http://www.codeproject.com/KB/aspnet...Repeaters.aspx
-
Re: Group a datalist?
Hi, thanks,
I'll tak a look at this and test it out.
Strick
-
Re: Group a datalist?
So you can use Linq? Why not just group your results?
Create a class that holds the month as a property, then
Code:
var numberGroups =
from ev in events
group ev by ev.EventDate.MonthName into m
select new EventWithMonth { //Properties };
And then the nested repeaters.