aspxgridview 从父级获取 MasterRowKeyValue
我正在尝试将网格嵌套在网格中。
为了填充最内部的网格,我需要来自网格的直接父级和网格父级的父级的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您确定处理详细信息的主 ASPxGridView 实例,则可以完成此操作。这可以使用以下代码来完成:
This can be done if you determine the master ASPxGridView instance for the processed detail. This can be done using the following code:
另一个可能的版本
Another possible version