Skip to main content
Tab

ASPxGridView.FindDetailRowTemplateControl(Int32, String) Method

Searches for the server control that the the specified detail row‘s template contains.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v23.2.dll

NuGet Package: DevExpress.Web

Declaration

public Control FindDetailRowTemplateControl(
    int visibleIndex,
    string id
)

Parameters

Name Type Description
visibleIndex Int32

The visible index of the detail row.

id String

A value that identifies the control within the specified detail row.

Returns

Type Description
Control

The control that the specified detail row’s template contains.

Remarks

The page’s hierarchy does not contain controls inside a detail row if a master row is collapsed. In this case, the FindDetailRowTemplateControl method returns null.

To access controls within the Detail Row template for a collapsed master row, expand this master row before you call the FindDetailRowTemplateControl method.

if (!ASPxGridViewMaster.DetailRows.IsVisible(ASPxGridViewMaster.FocusedRowIndex)) {
    ASPxGridViewMaster.DetailRows.ExpandRow(ASPxGridViewMaster.FocusedRowIndex)
}

Example

The following example demonstrates how to select rows in a detail grid when the master row selection changes.

View Example: How to select detail rows on master row selection

<dx:ASPxGridView ID="master" runat="server" AutoGenerateColumns="False" KeyFieldName="CategoryID"
    ClientInstanceName="master" OnCustomCallback="master_CustomCallback">
    <SettingsDetail ShowDetailRow="True" />
    <ClientSideEvents SelectionChanged="onMasterGridSelectionChanged" />
    <Columns>
        <dx:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="0" />
        <!-- ... -->
    </Columns>
    <Templates>
        <DetailRow>
            <dx:ASPxGridView ID="detail" runat="server" AutoGenerateColumns="False" KeyFieldName="ProductID"
                OnBeforePerformDataSelect="detail_BeforePerformDataSelect">
                <Columns>
                    <dx:GridViewCommandColumn ShowSelectCheckbox="true" VisibleIndex="0" />
                    <!-- ... -->
                </Columns>
            </dx:ASPxGridView>
        </DetailRow>
    </Templates>
</dx:ASPxGridView>
function onMasterGridSelectionChanged(s, e) {
    master.PerformCallback("select|" + e.visibleIndex + "|" + (e.isSelected ? "T" : ""));
}
protected void Page_Load(object sender, EventArgs e) {
    if(!IsPostBack) {
        master.DataBind();
        master.DetailRows.ExpandRow(0);
    }
}

protected void detail_BeforePerformDataSelect(object sender, EventArgs e) {
    detailData.SelectParameters["CategoryID"].DefaultValue = (sender as ASPxGridView).GetMasterRowKeyValue().ToString();
}
protected void master_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) {        
    string[] data = e.Parameters.Split('|');
    if(data.Length == 3 && data[0] == "select")
        ProcessDetailSelection(int.Parse(data[1]), data[2] == "T");     
}

void ProcessDetailSelection(int index, bool state) {
    ASPxGridView detail = master.FindDetailRowTemplateControl(index, "detail") as ASPxGridView;
    if(detail != null) {
        if(state)
            detail.Selection.SelectAll();
        else
            detail.Selection.UnselectAll();
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FindDetailRowTemplateControl(Int32, String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also