aspxgridview 从父级获取 MasterRowKeyValue

发布于 2024-09-18 18:39:56 字数 2787 浏览 6 评论 0原文

我正在尝试将网格嵌套在网格中。
为了填充最内部的网格,我需要来自网格的直接父级和网格父级的父级的 KeyValue。
如何从最外面的父级检索 MasterRowKeyValue?
我有 3 个网格,如下所示:

<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>

当为第一个详细网格调用 OnBeforePerformDataSelect 时,我设置选择参数 DefaultValue,如下所示:

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

对于最内部(第二个)嵌套网格,我需要将其中一个参数设置为 MasterRowKeyValue最外层网格的。
比如:

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

我如何实现这一目标?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

熊抱啵儿 2024-09-25 18:39:57

如果您确定处理详细信息的主 ASPxGridView 实例,则可以完成此操作。这可以使用以下代码来完成:

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

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();
    }
獨角戲 2024-09-25 18:39:57

另一个可能的版本

protected void gvMyGridView_BeforePerformDataSelect(object sender, EventArgs e)
    {
        var gvMyGridView = sender as ASPxGridView;
        var parentRow = gvMyGridView.NamingContainer as GridViewDetailRowTemplateContainer;
        odsChildDataSource.SelectParameters["Id"].DefaultValue = parentRow .KeyValue.ToString();
    }

Another possible version

protected void gvMyGridView_BeforePerformDataSelect(object sender, EventArgs e)
    {
        var gvMyGridView = sender as ASPxGridView;
        var parentRow = gvMyGridView.NamingContainer as GridViewDetailRowTemplateContainer;
        odsChildDataSource.SelectParameters["Id"].DefaultValue = parentRow .KeyValue.ToString();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文