I have a problem with the master/detail hierarchy in case of many to many relationship with the entity framework I use an object data source to bind the data to the grid and in the expand collapse command I use the parent item data key to fill the session and bind the data of the detail table so when I expand all the records in the detail they showed right but when I try to just add a new row to this detail the detail binds but the it shows the wrong records and this a copy of my aspx code
<TMS:TelerikGrid ID="gridScoutingProfiles" OnNeedDataSource="gridScoutingProfiles_NeedDataSource" OnDetailTableDataBind="gridScoutingProfiles_DetailTableDataBind" OnInsertCommand="gridScoutingProfiles_InsertCommand"OnItemCommand="gridScoutingProfiles_ItemCommand" runat="server" AllowAutomaticDeletes="true"AllowAutomaticInserts="true" AllowAutomaticUpdates="true" DataSourceID="objDSScoutingProfiles" AllowPaging="true" GridLines="Both"> <MasterTableView AutoGenerateColumns="false" DataKeyNames="ScoutingProfileID" CommandItemDisplay="Top"> <Columns> <Telerik:GridEditCommandColumn EditText="<%$Resources :Common,EditCommand %>" UniqueName="EditColumn" /> <Telerik:GridButtonColumn Text="<%$Resources :Common,DeleteCommand %>" CommandName="Delete" ConfirmText="<%$Resources :Common,DeleteRecordConfirmationMessage %>" /> <Telerik:GridTemplateColumn HeaderText="Scouting Profile Name" UniqueName="ScoutingProfileName" SortExpression="ScoutingProfileName"> <ItemTemplate> <asp:Label runat="server" ID="lblScoutingProfileName" Text='<%#Eval("ScoutingProfileName") %>'</asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox runat="server" Text='<%#Bind("ScoutingProfileName")%>' ID="txtScoutingProfileName</asp:TextBox> <TMS:RequiredFieldValidator ID="rfvScoutingProfileName" runat="server ControlToValidate="txtScoutingProfileName</TMS:RequiredFieldValidator> </EditItemTemplate> </Telerik:GridTemplateColumn> </Columns> <DetailTables> <Telerik:GridTableView CommandItemDisplay="Top DataKeyNames="SkillID" DataSourceID="objDSScoutingProfileSkills" Caption="Skills" AllowAutomaticDeletes="True" runat="server" AllowPaging="True" AllowAutomaticUpdates="true" AllowAutomaticInserts="true" AutoGenerateColumns="false"> <Columns> <Telerik:GridButtonColumn Text="<%$Resources :Common,DeleteCommand %>" CommandName="Delete" ConfirmText="<%$Resources :Common,DeleteRecordConfirmationMessage %>" /> <Telerik:GridTemplateColumn HeaderText="Skill Name" UniqueName="SkillName" SortExpression="SkillName"> <ItemTemplate> <asp:Label runat="server" ID="lblSkillName" Text='<%#Eval("SkillName") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <Telerik:RadComboBox runat="server" SelectedValue='<%#Bind("SkillID") %>' ID="cmbSkills" DataSourceID="objDSSkills" DataTextField="SkillName" DataValueField="SkillID"> </Telerik:RadComboBox> <TMS:RequiredFieldValidator ID="rfvSkillName" runat="server" ControlToValidate="cmbSkills"> </TMS:RequiredFieldValidator> </EditItemTemplate> </Telerik:GridTemplateColumn> </Columns> </Telerik:GridTableView> </DetailTables> </MasterTableView> </TMS:TelerikGrid>and this a copy of my cs code
protected void gridScoutingProfiles_ItemCommand(object source, GridCommandEventArgs e) { if (e.CommandName == "ExpandCollapse") { Session["scoutingProfileID"] = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ScoutingProfileID"].ToString(); } } protected void gridScoutingProfiles_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) { GridDataItem ParentItem = e.Item.OwnerTableView.ParentItem as GridDataItem; if (ParentItem != null) Session["scoutingProfileID"] = ParentItem.OwnerTableView.DataKeyValues[ParentItem.ItemIndex]["ScoutingProfileID"].ToString(); }
