Group by Month

Thread is closed for posting
1 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 11 Dec 2007 Link to this post

    Requirements

    RadGrid for ASP .NET version

    RadControls for ASP .NET AJAX version

    5.0.1 and later


    2008.1.415 and later
    .NET version

    2.0 and later
    Visual Studio version

    2005 and later
    Programming language

    C#
    Browser support

    all browsers supported by RadGrid


     

    PROJECT DESCRIPTION
    Grouping RadGrid’s data by month is quite a common request. The tricky part for implementing such functionality is to "treat" the date as object of type DateTime instead of String. Getting value as String (by applying formatting for example) will result in alphabetical sorting rather than in conjunction with the date values.

    Therefore one possible solution is to build our own DateTime object from the formatted date and then use this generated date as column in the group by. As we do not need the day from the DateTime object we will assign one particular day to all dates, for example 1. Thus we will have dates like 1/1/2007, 1/6/2005, 1/12/2004. This will let us ignore the day and group only by month and year.

    In the attached example two scenarios are implemented: one using SqlDataSource (demonstrating how you can convert the DateTime column in T-SQL select statement) and other using ObjectDataSource (demonstrating the usage of custom data container object).

Back to Top