|
-
Dec 15th, 2008, 01:41 PM
#1
Thread Starter
Fanatic Member
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
Last edited by stricknyn; Dec 15th, 2008 at 01:46 PM.
-
Dec 15th, 2008, 10:37 PM
#2
Hyperactive Member
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
-
Dec 17th, 2008, 11:39 AM
#3
Thread Starter
Fanatic Member
Re: Group a datalist?
Hi, thanks,
I'll tak a look at this and test it out.
Strick
-
Dec 23rd, 2008, 03:19 AM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|