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

Master Detail Grid Problem With Many to many relationShip and entity Framework

1 Answer 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mohamed
Top achievements
Rank 1
mohamed asked on 23 Nov 2010, 04:55 PM
  

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>

        {
            if (e.CommandName == "ExpandCollapse")
            {
                GridDataItem ParentItem = e.Item.OwnerTableView.ParentItem as GridDataItem;
                //if (ParentItem != null)
              //Session["scoutingProfileID"] = ParentItem.OwnerTableView.DataKeyValues[ParentItem.ItemIndex]["ScoutingProfileID"].ToString();
                Session["scoutingProfileID"] = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ScoutingProfileID"].ToString();
                //RadGrid gridScoutingProfiles = source as RadGrid;
                //gridScoutingProfiles.MasterTableView.DetailTables[0].DataBind();
            }







}

        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();
        }
 protected void gridScoutingProfiles_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "ExpandCollapse")
            {
                GridDataItem ParentItem = e.Item.OwnerTableView.ParentItem as GridDataItem;
                //if (ParentItem != null)
                //Session["scoutingProfileID"] = ParentItem.OwnerTableView.DataKeyValues[ParentItem.ItemIndex]["ScoutingProfileID"].ToString();
                Session["scoutingProfileID"] = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ScoutingProfileID"].ToString();
                //RadGrid gridScoutingProfiles = source as RadGrid;
                //gridScoutingProfiles.MasterTableView.DetailTables[0].DataBind();
            }


        }

        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();
        }
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();
       }

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 26 Nov 2010, 08:51 AM
Hello Mohamed,

Could you please elaborate a bit more. When you add a new record to the detail table is it added in the wrong detail table or the record is not added? Also does any error, javascript or server side, occurs? Also if you have an ajax, could you please disable it and let me know if the unwanted behavior still exists. Additionally it will be helpful if you could post your aspx page with the related code behind code. Thus we will be able to gather more details about your scenario and provide you with more to-the-point answer.
Looking forward for your reply.

Sincerely yours,
Radoslav
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
mohamed
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or