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

Bind Grid to deep object

2 Answers 73 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 01 Dec 2008, 06:36 PM
I have an entity object that contains entities with properties I wish to bind to grid columns.  When binding, I recieve the following exception:

DataBinding: 'EFPoC.OrderDetail+GridItem' does not contain a property with the name 'entity.PartNumber'.

However, my entity does have a property named 'entity' which contains a property named 'PartNumber'.

This seems like it should 'just work' so can anyone help me determine what I've missed? BTW, the exception is thrown when I make the call to CartGrid.DataBind();

Thanks in advance!
Regards, Scott

Here's my entity - I'm binding to a list of these.

public class GridEntity {  
   public bool Checked;  
   public CartItem entity;  

My grid is defined like this:
<telerik:RadGrid ID="CartGrid" runat="server"   
        GridLines="None"   
        Skin="Vista"   
        EnableViewState="true" 
        OnItemCommand="CartGrid_OnItemCommand">  
        <HeaderContextMenu EnableTheming="True">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </HeaderContextMenu> 
        <MasterTableView AutoGenerateColumns="false"   
            DataKeyNames="entity.PartNumber,entity.ItemLegalName"   
            ClientDataKeyNames="entity.PartNumber,entity.ItemLegalName">  
            <Columns> 
                <telerik:GridCheckBoxColumn DataField="Checked" HeaderText="Selected" > 
                    <HeaderStyle Width="10%" /> 
                </telerik:GridCheckBoxColumn> 
                <telerik:GridBoundColumn DataField="entity.PartNumber" HeaderText="Kit #">  
                    <HeaderStyle Width="20%" /> 
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="entity.ItemLegalName" HeaderText="Kit Name">  
                    <HeaderStyle Width="55%" /> 
                </telerik:GridBoundColumn> 
                <telerik:GridButtonColumn ButtonType="PushButton" CommandName="removeFromCart" CommandArgument="0" Text="remove item" ConfirmDialogType="RadWindow">  
                    <HeaderStyle Width="15%" /> 
                </telerik:GridButtonColumn> 
            </Columns> 
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
        </MasterTableView> 
        <FilterMenu EnableTheming="True">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </FilterMenu> 
    </telerik:RadGrid> 

I'm using this loading code:
using (CartServiceClient client = new CartServiceClient())  
{  
    Cart cart = client.GetCart(UserEntityID);  
    var entityList = from item in cart.CartItems   
        select new GridItem {  
            Checked = false,  
            entity = item   
        };  
 
    CartGrid.DataSource = entityList;  
    CartGrid.DataBind();  

2 Answers, 1 is accepted

Sort by
0
Scott
Top achievements
Rank 1
answered on 01 Dec 2008, 09:46 PM
I worked around the problem by flatening out the entity with an anonymous object... 

using (CartServiceClient client = new CartServiceClient())  
{  
    Cart cart = client.GetCart(UserEntityID);  
    var entityList =   
        from item in cart.CartItems  
        select new 
        {  
            Checked = false,  
            PartNumber = item.PartNumber,  
            ItemLegalName = item.ItemLegalName,  
            entity = item  
        };  
 
    viewEntities = entityList;  

I tried turning on AutoColumnGeneration and still found that the properties of the 'entity' property are not reflected and turned into columns. 

Is deep binding a known limitation?
0
Rosen
Telerik team
answered on 03 Dec 2008, 02:46 PM
Hello Scott,

The behavior you are experiencing is due to the fact that nested object are currently not supported as DataKeyName values. However, I have added this to our product backlog for future implementation.

Please excuse us for the inconvenience this may caused you.

Kind regards,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Scott
Top achievements
Rank 1
Answers by
Scott
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or