I have a Grid named gvModules with a nested grid called gvFields. The gvModules uses the DataKey ItemTypeID that I need when a new record is added to gvFields. I am trying to access that DataKey from the insert statement in the gvFields ItemCommand method. I've tried the examples given on the forums and in the documentation without avail. I would welcome any additional direction.
ASPX
C#
What I always get is 'Cannot find parent item'.
ASPX
<telerik:RadGrid ID="gvModules" runat="server" AutoGenerateColumns="False" DataSourceID="dsModules" GridLines="None" AutoGenerateEditColumn="True" OnItemDataBound="gvModules_OnItemDataBoundHandler" Skin="Windows7" AllowFilteringByColumn="True" AllowSorting="True"> <MasterTableView DataKeyNames="ItemTypeID" DataSourceID="dsModules"> ---- <NestedViewSettings DataSourceID="dsFields"> <ParentTableRelation> <telerik:GridRelationFields DetailKeyField="ItemTypeID" MasterKeyField="ItemTypeID" /> </ParentTableRelation> </NestedViewSettings> <NestedViewTemplate> <telerik:RadGrid ID="gvFields" runat="server" DataSourceID="dsFields" AutoGenerateEditColumn="True" GridLines="None" Skin="Windows7" OnItemDataBound="gvFields_OnItemDataBoundHandler" OnItemCommand="gvFields_ItemCommand" OnItemUpdated="gvFields_ItemUpdated" AllowSorting="True"> <MasterTableView CommandItemDisplay="TopAndBottom" AutoGenerateColumns="False" DataSourceID="dsFields" DataKeyNames="FieldID"> ----- </MasterTableView> </telerik:RadGrid> </NestedViewTemplate> </MasterTableView> </telerik:RadGrid>C#
protected void gvFields_ItemCommand(object source, GridCommandEventArgs e) { if (e.CommandName == RadGrid.PerformInsertCommandName) { GridEditableItem editedItem = e.Item as GridEditableItem; //PARAM ITEM TYPE ID GridDataItem parentItem = (GridDataItem)(e.Item.OwnerTableView.ParentItem); if (parentItem != null) { string itemType = ""; itemType = parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["ItemTypeID"].ToString(); lblTmp.Text += "Item Type ID = " + itemType; //dsFields.InsertParameters["ItemTypeID"].DefaultValue = parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["ItemTypeID"].ToString(); } else { lblError.Text += "Cannot find parent item"; } } }What I always get is 'Cannot find parent item'.