Skip to main content
Tab

ASPxGridView.GetDetailRowKeyValue(Control) Method

Gets the key value of the grid’s row that is the master row for the specified control used to display detail data.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public static object GetDetailRowKeyValue(
    Control control
)

Parameters

Name Type Description
control Control

A control that represents detail data.

Returns

Type Description
Object

An object that uniquely identifies the master row containing the specified detail control.

Remarks

In master-detail scenarios, when ASPxGridView is used as a master grid that displays details within its detail rows, you can visualize detail data using any desired control. The primary task in these scenarios is to identify a master row when a control that displays the details should be bound to its data.

GridView-GetDetailRowKey

If a detail control is not ASPxGridView, you can use a master grid’s GetDetailRowKeyValue method to determine in which master row the specified detail control is currently instantiated. This method accepts a detail control instance as a parameter and returns the corresponding master row’s key value.

protected void GridView1_DataBinding (object sender, EventArgs e) {
        //Standard GridView is used as a detail control.
        GridView detailGrid = sender as GridView;
        detailGrid.DataSource = dsDetailView;
        dsDetailView.SelectParameters["CategoryID"].DefaultValue = ASPxGridView.GetDetailRowKeyValue(detailGrid).ToString();
    }

Example

In master-detail scenarios, when ASPxGridView is used as a master grid that displays details within its detail rows, you can visualize detail data using any desired control. The main task in these scenarios is to identify a master row when a control that displays the details should be bound to its data.The simplest way to visualize detail data is to use ASPxGridView, because this control has the GetMasterRowKeyValue() method that automatically obtains the corresponding master row’s key value from a master ASPxGridView. For other cases (when a detail control is not ASPxGridView), you can bring a detail control in correlation with its master row by using a specifically implemented static method - GetDetailRowKeyValue(Control) This method accepts a detail control instance as a parameter and returns the corresponding master row's key value: GetDetailRowKeyValue(Control)

This example demonstrates how to use the GetMasterRowKeyValue() and GetDetailRowKeyValue(Control) methods.

object keyValue = ASPxGridView.GetDetailRowKeyValue(treeList);
Dim keyValue As Object = ASPxGridView.GetDetailRowKeyValue(treeList)
<dx:ASPxGridView ID="masterGrid" runat="server" AutoGenerateColumns="False" DataSourceID="dsMainGrid"
    Width="700px" KeyFieldName="CategoryID">
    <Templates>
        <DetailRow>
            <dx:ASPxPageControl ID="ASPxPageControl1" runat="server" ActiveTabIndex="0" Width="100%">
                <TabPages>
                    <dx:TabPage>
                        <ContentCollection>
                            <dx:ContentControl ID="ContentControl1" runat="server">
                                <dx:ASPxTreeList ID="ASPxTreeList1" runat="server" AutoGenerateColumns="False"      
                                                 DataSourceID="dsTreeList" KeyFieldName="EmployeeID" 
                                                 OnInit="ASPxTreeList1_Init" ParentFieldName="ReportsTo"
                                                 Width="100%">
                                    <Columns>
                                        <dx:TreeListTextColumn FieldName="FirstName" />
                                        <dx:TreeListTextColumn FieldName="LastName" />
                                        <dx:TreeListTextColumn FieldName="Title" />
                                    </Columns>
                                </dx:ASPxTreeList>
                            </dx:ContentControl>
                        </ContentCollection>
                    </dx:TabPage>
                    <dx:TabPage>
                        <ContentCollection>
                            <dx:ContentControl ID="ContentControl3" runat="server">
                                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                                              DataKeyNames="ProductID" Style="margin-right: 0px" 
                                              OnDataBinding="GridView1_DataBinding">
                                    <Columns>
                                        <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" />
                                        <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" />
                                        <asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock" />
                                        <asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder" />
                                    </Columns>
                                </asp:GridView>
                            </dx:ContentControl>
                        </ContentCollection>
                    </dx:TabPage>
                    <dx:TabPage>
                        <ContentCollection>
                            <dx:ContentControl ID="ContentControl2" runat="server">
                                <dx:ASPxGridView ID="detailGrid" runat="server" AutoGenerateColumns="False" DataSourceID="dsDetail"
                                    KeyFieldName="ProductID" OnBeforePerformDataSelect="detailGrid_BeforePerformDataSelect"
                                    Width="100%">
                                    <Columns>
                                        <dx:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="1">
                                        </dx:GridViewDataTextColumn>
                                        <dx:GridViewDataTextColumn FieldName="SupplierID" VisibleIndex="2">
                                        </dx:GridViewDataTextColumn>
                                        <dx:GridViewDataTextColumn FieldName="CategoryID" VisibleIndex="3">
                                        </dx:GridViewDataTextColumn>
                                        <dx:GridViewDataTextColumn FieldName="QuantityPerUnit" VisibleIndex="4">
                                        </dx:GridViewDataTextColumn>
                                    </Columns>
                                </dx:ASPxGridView>
                            </dx:ContentControl>
                        </ContentCollection>
                    </dx:TabPage>
                </TabPages>
            </dx:ASPxPageControl>
        </DetailRow>
    </Templates>
    <Columns>
        <dx:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" >
            <EditFormSettings Visible="False" />
        </dx:GridViewDataTextColumn>
        <dx:GridViewDataTextColumn FieldName="CategoryName" />
        <dx:GridViewDataTextColumn FieldName="Description" />
    </Columns>
    <SettingsDetail ShowDetailRow="True" />
</dx:ASPxGridView>
protected void ASPxTreeList1_Init (object sender, EventArgs e) {
    ASPxTreeList treeList = sender as ASPxTreeList;
    object keyValue = ASPxGridView.GetDetailRowKeyValue(treeList);
    if (keyValue.Equals(2) || keyValue.Equals(5))
        treeList.RootValue = keyValue;
}

protected void detailGrid_BeforePerformDataSelect (object sender, EventArgs e) {
    ASPxGridView grid = sender as ASPxGridView;
    Session["CategoryID"] = grid.GetMasterRowKeyValue();
}

protected void GridView1_DataBinding (object sender, EventArgs e) {
    GridView gridView = sender as GridView;
    gridView.DataSource = dsDetailView;
    dsDetailView.SelectParameters["CategoryID"].DefaultValue = ASPxGridView.GetDetailRowKeyValue(gridView).ToString();
}
See Also