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

Anonymous type grid binding issue

3 Answers 170 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 29 Nov 2010, 09:45 PM
Hello!
I have a web service that returns a collection of anonymous types. Here is an example of something that works for me.

var allMyFoo = (from w in fooService.GiveMeFoo()
                 select new
                 {
                   ID = w.ID,
                   Foo = w.Foo.Name                        
                 });
 
var myFooCount = fooService.CountMyFoo();
return new Dictionary<string, object> {
  {"foo", allMyFoo},
  {"fooCount", myFooCount}
};

in aspx...

<telerik:GridBoundColumn UniqueName="FooName" SortExpression="Foo.Name" DataField="Foo" HeaderText="Foo" DataType="System.String">
</telerik:GridBoundColumn>
But this is what I wanted to do with bolded changes in code and aspx

var allMyFoo = (from w in fooService.GiveMeFoo()
                 select new
                 {
                   ID = w.ID,
                   Foo = new { Name = w.Foo.Name }
                 });
  
var myFooCount = fooService.CountMyFoo();
return new Dictionary<string, object> {
  {"foo", allMyFoo},
  {"fooCount", myFooCount}
};
 
in aspx...
 
<telerik:GridBoundColumn UniqueName="FooName" SortExpression="Foo.Name" DataField="Foo.Name" HeaderText="Foo" DataType="System.String">
</telerik:GridBoundColumn>

Could you tell me why the grid doesn't display the Name of Foo when I try the second example?

3 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 02 Dec 2010, 12:20 PM
Hello Mike,

RadGrid does not support binding to sub objects (in the form Property.SubProperty) when client-side databinding is used.

Veli
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Tajes
Top achievements
Rank 1
answered on 28 Feb 2011, 03:07 PM
Hello,
   Is there any way to disable client-side databinding, in order to binding to sub objects?

Thanks
0
Marin
Telerik team
answered on 03 Mar 2011, 06:10 PM
Hi Tajes,

You can bind to sub object using the standard NeedDataSource event for the grid as shown in this help article.

Kind regards,
Marin
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Veli
Telerik team
Tajes
Top achievements
Rank 1
Marin
Telerik team
Share this question
or