Results 1 to 4 of 4

Thread: Group a datalist?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    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.

  2. #2
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 2003
    Location
    Back in the doghouse
    Posts
    294

    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Re: Group a datalist?

    Hi, thanks,

    I'll tak a look at this and test it out.

    Strick

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width