views:

139

answers:

1

Hi,

I am trying to nest a grid within a grid.
To populate the most inner grid i need the KeyValue from both the Grids' direct parent, and the parent of the Grids' parent.
How can i retrieve the MasterRowKeyValue from the outter most parent?
I have 3 grids nested like so:

<dxwgv:ASPxGridView ID="gridParents" runat="server" ObjectDataSource="odsParents" KeyFieldName="ParentId">
 <SettingsDetail ShowDetailRow="true" />
 <Columns>
  <dx:GridViewDataColumn FieldName="ParentIdId" Visible="false" />
  <dx:GridViewDataColumn FieldName="Title" />
 </Columns>
 <Templates>
  <DetailRow>
   <dxwgv:ASPxGridView ID="gridParentsChilren" runat="server" ObjectDataSource="odsParentsChildren" KeyFieldName="ChildId" OnBeforePerformDataSelect="gridParentsChilren_DataSelect">
    <SettingsDetail ShowDetailRow="true" IsDetailGrid="true" />
    <Columns>
     <dx:GridViewDataColumn FieldName="ChildId" Visible="false" />
     <dx:GridViewDataColumn FieldName="Title" />
    </Columns>
    <Templates>
     <dxwgv:ASPxGridView ID="gridParentsChilrenRoles" runat="server" ObjectDataSource="odsParentsChildrenRoles" KeyFieldName="RoleId" OnBeforePerformDataSelect="gridParentsChilrenRoles_DataSelect">
      <SettingsDetail ShowDetailRow="true" IsDetailGrid="true" />
      <Columns>
       <dx:GridViewDataColumn FieldName="RoleId" Visible="false" />
       <dx:GridViewDataColumn FieldName="Title" />
      </Columns>
     </dxwgv:ASPxGridView>
    </Templates>
   </dxwgv:ASPxGridView>
  </DetailRow>
 </Templates>
</dxwgv:ASPxGridView>
<asp:ObjectDataSource id="odsParents" runat="server" SelectMethod="GetParents" />
<asp:ObjectDataSource id="odsParentsChildren" runat="server" SelectMethod="GetParentsChildren">
 <SelectParameters>
  <asp:Parameter Name="parentid" Type="Object" />
 </SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource id="odsParentsChildrenRoles" runat="server" SelectMethod="GetParentsRoles">
 <SelectParameters>
  <asp:Parameter Name="childid" Type="Object" />
  <asp:Parameter Name="parentid" Type="Object" />
 </SelectParameters>
</asp:ObjectDataSource>

When the OnBeforePerformDataSelect is called for the first Detail grid, i set the select parameters DefaultValue like this:

odsParentsChildren.SelectParameters["parentid"].DefaultValue = ((ASPxGridView)sender).GetMasterRowKeyValue().ToString();

For the most inner (the second) nested grid, i need to set one of my parameters to the MasterRowKeyValue of the most outter grid.
Something like:

odsParentsChildrenRoles.SelectParameters["childid"].DefaultValue = ((ASPxGridView)sender).GetMasterRowKeyValue().ToString();
odsParentsChildrenRoles.SelectParameters["parentid"].DefaultValue = ((ASPxGridView)sender).Master.GetMasterRowKeyValue().ToString();

How do I achieve this?

+1  A: 

Hi,

This can be done if you determine the master ASPxGridView instance for the processed detail. This can be done using the following code:

protected void ASPxGridView1_BeforePerformDataSelect(object sender, EventArgs e) {
        ASPxGridView subDetail = sender as ASPxGridView;
        GridViewDetailRowTemplateContainer container = subDetail.NamingContainer as GridViewDetailRowTemplateContainer;
        ASPxGridView detail = container.Grid;
        odsParentsChildrenRoles.SelectParameters["parentid"].DefaultValue = detail.GetMasterRowKeyValue();
    }
DevExpress Team