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

radgrid bind anonymoustype

2 Answers 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wired_Nerve
Top achievements
Rank 2
Wired_Nerve asked on 14 Oct 2010, 04:32 PM
I have a rad grid that I am using the needdatasource event to populate.
I have a linq query that returns a set of information.
I refered to this link for aid: http://www.telerik.com/help/openaccess-orm/openaccess-tasks-howto-execute-query-anonimous-type.html
When I run my code I get an ugly error:
"

DataBinding: 'System.Data.Linq.SqlClient.ObjectReaderCompiler+Group`2[[<>f__AnonymousType1`4[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], TIPWebIT, Version=2010.1.415.0, Culture=neutral, PublicKeyToken=null],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' does not contain a property with the name 'ItemNumber'.

"

Here is the grid:

 

 

 

<telerik:RadGrid ID="RadGridInventory" runat="server" AllowPaging="True" AllowSorting="True"
          GridLines="None" OnNeedDataSource="RadGridInventory_NeedDataSource" 
          AutoGenerateColumns="False">
          <MasterTableView CommandItemDisplay="None">
              <CommandItemSettings ExportToPdfText="Export to Pdf" />
              <Columns>
                  <telerik:GridTemplateColumn DataField="ItemNumber" HeaderText="Product Number" SortExpression="ItemNumber"
                      UniqueName="ItemNumber">
                      <ItemTemplate>
                          <asp:Label ID="ItemNumberLabel" runat="server" SkinID="EditForms" Text='<%# Eval("ItemNumber") %>' />
                      </ItemTemplate>
                  </telerik:GridTemplateColumn>
                  <telerik:GridTemplateColumn DataField="ItemName" HeaderText="Product" SortExpression="ItemName"
                      UniqueName="ItemName">
                      <ItemTemplate>
                          <asp:Label ID="ItemNameLabel" runat="server" SkinID="EditForms" Text='<%# Eval("ItemName") %>' />
                      </ItemTemplate>
                  </telerik:GridTemplateColumn>
                  
              </Columns>
          </MasterTableView>
      </telerik:RadGrid>

Here is the linq to sql statement that is used to populate the grid:
protected void RadGridInventory_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
       {
           TIPWebITLibrary.DAL.TIPWebITDataContext DC = new TIPWebITLibrary.DAL.TIPWebITDataContext();
           var RoomInventory = (from items in DC.tblTechItems
                                join inventory in DC.tblTechInventories on items.ItemUID equals inventory.ItemUID
                                where inventory.EntityTypeUID == 2 && inventory.EntityUID == Convert.ToInt32(HiddenFieldEntity.Value)
                                group items.ItemNumber by
                                new { items.ItemNumber, items.ItemName, inventory.EntityTypeUID, inventory.EntityUID } into g
                                select g);
           this.RadGridInventory.DataSource = RoomInventory.ToList();
       }

Any ideas on what I am doing wrong here?


Here is the result set when I run my linq statement in LinqPAD:

Key=

{ ItemNumber = 1251341, ItemName = C510 Webcam, EntityTypeUID = 2, EntityUID = 1 }

ItemNumber

1251341

ItemName

C510 Webcam

EntityTypeUID

2

EntityUID

1

 

1251341

Key=

{ ItemNumber = 1251343, ItemName = MacBook, EntityTypeUID = 2, EntityUID = 1 }

ItemNumber

1251343

ItemName

MacBook

EntityTypeUID

2

EntityUID

1

 

1251343

1251343

2 Answers, 1 is accepted

Sort by
0
Wired_Nerve
Top achievements
Rank 2
answered on 14 Oct 2010, 04:49 PM
I got it to work, but I am not happy with the way the code looks at all.. Does not seem "right..." if you know what I mean...

TIPWebITLibrary.DAL.TIPWebITDataContext DC = new TIPWebITLibrary.DAL.TIPWebITDataContext();
  
            var RoomInventory = (from items in DC.tblTechItems
                                 join inventory in DC.tblTechInventories on items.ItemUID equals inventory.ItemUID
                                 where inventory.EntityTypeUID == 2 && inventory.EntityUID == Convert.ToInt32(HiddenFieldEntity.Value)
                                 group items.ItemNumber by
                                 new { items.ItemNumber, items.ItemName, inventory.EntityTypeUID, inventory.EntityUID } into g
  
                                 select new { g.Key.ItemName, g.Key.ItemNumber, g.Key.EntityTypeUID, g.Key.EntityUID });
0
Vasil
Telerik team
answered on 21 Oct 2010, 10:13 AM
Hi Warren,

At this moment, we could not think of a better solution than what you came with.
The first linqtosql you used, returns IQueryable<SomeDataClass>, and the DataBinder does not know how to handle it.

All the best,
Vasil
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Wired_Nerve
Top achievements
Rank 2
Answers by
Wired_Nerve
Top achievements
Rank 2
Vasil
Telerik team
Share this question
or