Greetings,
I am implementing a grid using the manual crud example shown in your demo at: http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/programaticlinqupdates/defaultcs.aspx. However, for my scenario I have an entity reference key for one of my columns for which I populate a GridDropDownColumn using a DomainDataSource object as shown in the code block below:
The problem that I am having is that my reference entity for the dropdown list is not been updated when I select a new value during the Update. During Insert the reference is set correctly to the selected value using the ExtractValues method of the GridEditableItem. Please advise of changes I could make to ensure my reference is updated when using the UpdateValues of the GridEditableItem method as shown below. I have already included the entity reference (SicCode) when I get the object for update. I do not understand how the UpdateValues work behind the scense and would appreciate any insight you can share regarding the handling of foreign key columns.
Thanks!
I am implementing a grid using the manual crud example shown in your demo at: http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/programaticlinqupdates/defaultcs.aspx. However, for my scenario I have an entity reference key for one of my columns for which I populate a GridDropDownColumn using a DomainDataSource object as shown in the code block below:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" OnColumnCreated="RadGrid1_ColumnCreated" OnItemCreated="RadGrid1_ItemCreated" OnItemDataBound="RadGrid1_ItemDataBound" OnInsertCommand="RadGrid1_InsertCommand" OnUpdateCommand="RadGrid1_UpdateCommand" OnDeleteCommand="RadGrid1_DeleteCommand" AllowFilteringByColumn="True" GridLines="None" > <HeaderContextMenu EnableAutoScroll="True"></HeaderContextMenu> <MasterTableView HierarchyDefaultExpanded="false" HierarchyLoadMode="ServerBind" AllowSorting="true" AutoGenerateColumns="false" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage" DataKeyNames="SICItemID" > <Columns> <telerik:GridEditCommandColumn ButtonType="ImageButton" /> <telerik:GridBoundColumn DataField="SICItemID" HeaderText="ID" UniqueName="SICItemID" SortExpression="SICItemID" Visible="false" ReadOnly="true" Display="false" /> <telerik:GridBoundColumn DataField="ItemName" HeaderText="Question" UniqueName="ItemName" ItemStyle-Wrap="true" ItemStyle-Width="300" SortExpression="ItemName" MaxLength="2000" ReadOnly="false" Display="true" /> <telerik:GridDropDownColumn FooterText="SIC Code" UniqueName="ddlSICCodes" ReadOnly="false" ListTextField="SICCode1" ListValueField="SICID" DataSourceID="ddsGetSICCodes" HeaderText="SIC Code" DataField="SICCode.SICID" AllowSorting="true" DefaultInsertValue=""> </telerik:GridDropDownColumn>
</Columns> <EditFormSettings> <EditColumn UniqueName="EditCommandColumn1"></EditColumn> </EditFormSettings> </MasterTableView> <ClientSettings AllowExpandCollapse="true" EnableRowHoverStyle="true" /> </telerik:RadGrid> <cc1:DomainDataSource runat="server" ID="ddsGetSICCodes" DomainServiceTypeName="ID.DomainServices.ListTypesDomainService" SelectMethod="GetSicCodes" EnableUpdate="true" EnableInsert="false" EnableDelete="false" > <SelectParameters> <asp:SessionParameter Name="Scope" SessionField="MyScope" DefaultValue="" ConvertEmptyStringToNull="true" DbType="Guid" /> </SelectParameters> </cc1:DomainDataSource>The problem that I am having is that my reference entity for the dropdown list is not been updated when I select a new value during the Update. During Insert the reference is set correctly to the selected value using the ExtractValues method of the GridEditableItem. Please advise of changes I could make to ensure my reference is updated when using the UpdateValues of the GridEditableItem method as shown below. I have already included the entity reference (SicCode) when I get the object for update. I do not understand how the UpdateValues work behind the scense and would appreciate any insight you can share regarding the handling of foreign key columns.
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) { GridEditableItem editedItem = e.Item as GridEditableItem; try { ListTypesDomainService lds = new ListTypesDomainService(); Guid sicItemID = new Guid(editedItem.GetDataKeyValue("SICItemID").ToString()); var updateSicItem = lds.GetSicItem(sicItemID); if (updateSicItem != null) { editedItem.UpdateValues(updateSicItem); lds.SaveChanges(); } } catch (Exception ex) { ProcessException(RadGrid1, ex); e.Canceled = true; } }Thanks!