This is a migrated thread and some comments may be shown as answers.

Grid Group By Field with Anonymous Type

2 Answers 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MFitzpatrick
Top achievements
Rank 1
MFitzpatrick asked on 17 Nov 2011, 06:38 PM
It seems that as of the Q3 release I am no longer able to add a GridGroupByField in a radgrid when the radgrid's datasource is a list of anonymous type objects.

Here is the group by expressions section in the grid:

<GroupByExpressions>
              <tk:GridGroupByExpression>
                <SelectFields>
                  <tk:GridGroupByField FieldAlias="Sent" FieldName="DateSent" FormatString="{0:D}" HeaderValueSeparator=" on: "></tk:GridGroupByField>
                </SelectFields>
                <GroupByFields>
                  <tk:GridGroupByField FieldName="DateSent" FormatString="{0:D}" SortOrder="Descending" ></tk:GridGroupByField>
                </GroupByFields>
              </tk:GridGroupByExpression>
            </GroupByExpressions>


The following is the anonymous type object declaration from the code behind:
oList.Add(New With {Key .SysID = message.SysID, .From = sender, .Subject = message.EmailSmsLog.Subject, _
                    .MailIcon = emailIcon, .DateSent = dateSent, .TimeSent = timeSent, _
                    .IsRead = message.IsRead})
I then assign the datasource of the radgrid as oList

The exception I get is:
Telerik.Web.UI.ParseException: No property or field 'DateSent' exists in type 'Object'

When I take the group by expressions out of the radgrid, everything works fine.

This code worked in previous versions of the control.

Can anyone confirm that this is a problem in Q3.

Thanks

Mike

2 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 21 Nov 2011, 10:20 AM
Hello Mfitzpatrick,

Could you please try creating the List of anonymous types directly instead of boxing the anonymous types into the list of objects. For example:
Public Function CreateEmptyList(Of T)(ByVal unused As T) As List(Of T)
    Return New List(Of T)()
  End Function
 
  Dim list = CreateEmptyList(New With {Key .SysID = message.SysID, .From = sender, .Subject = message.EmailSmsLog.Subject, _
                    .MailIcon = emailIcon, .DateSent = dateSent, .TimeSent = timeSent, _
                    .IsRead = message.IsRead}
)

Additionally In Q3 2011 release we have a new Linq based grouping which is turned on by default. This type of grouping has a huge performance optimization and internally uses Dynamic Linq for grouping. Also this grouping is controlled by the MasterTableView.EnableLinqGrouping property(default value is true). More information you could find here:
http://blogs.telerik.com/aspnet-ajax/posts/11-11-08/super-charged-performance-optimizations-for-telerik-s-asp-net-ajax-grid-in-q3-2011.aspx
To avoid the exception you could set the RadGrid.MasterTableView.EnableLinqGrouping property to "false". Please give it try and let me know if the issue still persists.

Looking forward for your reply.

Kind regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
MFitzpatrick
Top achievements
Rank 1
answered on 21 Nov 2011, 02:03 PM
Your suggestion of creating the list directly fixed my issue.

Thanks for replying so quickly.

Mike
Tags
Grid
Asked by
MFitzpatrick
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
MFitzpatrick
Top achievements
Rank 1
Share this question
or