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

Bind Lookup value to Object datasource

1 Answer 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris Vrolijk
Top achievements
Rank 1
Iron
Chris Vrolijk asked on 15 Sep 2010, 07:33 AM

Hi,


I'm trying to use a grid to bind to an object data source that receives tis data from EF4.

I run into problems when I try to edit a column that is an associated entity.


I have the following two entities:

Register_App and

App

Register_App is associated to App. Thus Register_App has a property App which in turn has an ID.


I would like to display a dropdown combo so I can select the appropriate App and this infpo is persisted to the


object data source.


I made the following grid column:



<telerik:GridDropDownColumn ListTextField="Name" ListValueField="Id" DataSourceID="odsApps" 
HeaderText="App" DataField="App.ID"
 DropDownControlType="RadComboBox"></telerik:GridDropDownColumn>




It works fine in display mode. The App is bound based on the DataField App.ID, and the correct Name is displayed.

When I turn to edit mode, all is wel again. A combobox is displayed with all the Apps and the correct one is


displayed. When I try to save the data I get the following error:



System.InvalidOperationException: Could not find a property named 'App.ID' on the type specified by the
DataObjectTypeName property in ObjectDataSource 'odsRegApps'. at
System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type dataObjectType, IDictionary inputParameters) at
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary
oldValues) at System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues,
DataSourceViewOperationCallback callback) at Telerik.Web.UI.GridTableView.PerformUpdate(GridEditableItem
editedItem, Boolean suppressRebind) at Telerik.Web.UI.GridCommandEventArgs.ExecuteCommand(Object source)

I am surprised that the property App.ID is resolved in Display mode and Edit mode but not during save. Do you know


what I'm doing wrong?


Any help is greatly appreciated,

best regards,

Chris Vrolijk



P.S. Below I included my entire control:


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AdminApps.ascx.cs"
 
Inherits="ActuIT.Futurama.ManagementSite.RegisterAdminAppsControl" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:ObjectDataSource ID="odsRegApps" runat="server"
 
DataObjectTypeName="ActuIT.Futurama_Vision.EFDataLayer.Register_App"
    SelectMethod="GetRegisterApps" TypeName="ActuIT.Futurama_Vision.Business.Register" UpdateMethod="UpdateApp"
    DeleteMethod="DeleteApp" InsertMethod="InsertApp" >
    </asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsPAs" runat="server"
 
DataObjectTypeName="ActuIT.Futurama_Vision.EFDataLayer.Register_PA"
    SelectMethod="GetPAs" TypeName="ActuIT.Futurama_Vision.Business.Register" ></asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsPUVs" runat="server"
 
DataObjectTypeName="ActuIT.Futurama_Vision.EFDataLayer.Register_PUV"
    SelectMethod="GetPUVs" TypeName="ActuIT.Futurama_Vision.Business.Register"></asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsApps" runat="server" DataObjectTypeName="ActuIT.Futurama_Vision.EFDataLayer.App"
    SelectMethod="GetApps" TypeName="ActuIT.Futurama_Vision.Business.Vision" ></asp:ObjectDataSource>
<telerik:RadGrid ID="gridApps" runat="server"
    AllowAutomaticDeletes="True"
    AllowPaging="True"
    AutoGenerateColumns="True"
    AllowAutomaticUpdates ="true"
    AllowAutomaticInserts = "true"
    DataSourceID="odsRegApps"
   >
    <MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="False" DataKeyNames="Id"
 
DataSourceID="odsRegApps">
        <RowIndicatorColumn>
            <HeaderStyle Width="20px" />
        </RowIndicatorColumn>
        <ExpandCollapseColumn>
            <HeaderStyle Width="20px" />
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
 
HeaderText="Edit" >
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" UniqueName="DeleteColumn"
 
ConfirmText="Are you sure you want to delete this application?" ConfirmTitle="Confirm Delete"
 
ConfirmDialogType="Classic" HeaderText="Delete">
            </telerik:GridButtonColumn>
            <telerik:GridBoundColumn DataField="Id" UniqueName="Id" HeaderText="Register ID" Visible="true"
 
ReadOnly="true">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Naam">
            </telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn UniqueName="UseXMLData" DataField="UseXMLData"
            HeaderText="UseXMLData"  />
            <telerik:GridBoundColumn  ColumnEditorID="txtDocument" DataField="Document" UniqueName="Document"
 
HeaderText="Document">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Folder" UniqueName="Folder" HeaderText="Folder">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="WebService" UniqueName="WebService" HeaderText="WebService">
            </telerik:GridBoundColumn>
            <telerik:GridDropDownColumn ListTextField="Name" ListValueField="Id" DataSourceID="odsApps" 
 
HeaderText="App" DataField="App.ID"
 DropDownControlType="RadComboBox"></telerik:GridDropDownColumn>
            <telerik:GridDropDownColumn ListTextField="Code" ListValueField="Id" DataSourceID="odsPAs" 
 
HeaderText="PA" DataField="Register_PA.Id"
 DropDownControlType="RadComboBox"></telerik:GridDropDownColumn>
            <telerik:GridDropDownColumn ListTextField="Code" ListValueField="Id" DataSourceID="odsPUVs" 
 
HeaderText="PUV" DataField="Register_PUV.Id"
 DropDownControlType="RadComboBox"></telerik:GridDropDownColumn>
 
        </Columns>
         <EditFormSettings ColumnNumber="2" CaptionDataField="Name" InsertCaption="Voeg register applicatie toe"
 
EditFormType="AutoGenerated">
            <EditColumn InsertText="Insert" EditText="Edit application id #:" EditFormColumnIndex="0"
 
UpdateText="Application updated" UniqueName="InsertCommandColumn1" CancelText="Cancel"
 
ButtonType="ImageButton"></EditColumn>
        </EditFormSettings>
            </MasterTableView>
</telerik:RadGrid>




1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 20 Sep 2010, 02:36 PM
Hello Chris,

You can have a one-way (read-only) binding to nested properties only. This means RadGrid will bind to the App.Id subproperty because it can evalueate the expression App.Id using Eval(). Your nested data values are properly fetched and the relations are built.

This is not the case with two-way binding, however. You cannot automatically modify the value of a nested property, much the same as the Bind() expression will not work with nested properties. You have to modify either modify your entities so that the App.Id property is mapped to a first-level property in the Register_App entity (and you can use automatic data operations with the GridDropDownColumn), or implement your own Update / Insert logic to update your entities manually. The latter can be done from RadGrid's UpdateCommand / InsertCommand events, where you need to set e.Canceled = true and update / insert your data manually.

Greetings,
Veli
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
Chris Vrolijk
Top achievements
Rank 1
Iron
Answers by
Veli
Telerik team
Share this question
or