aspnet-devexpress-dot-web-dot-aspxgridview-dot-finddetailrowtemplatecontrol-x28-system-dot-int32-system-dot-string-x29.md
Searches for the server control that the the specified detail row‘s template contains.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
public Control FindDetailRowTemplateControl(
int visibleIndex,
string id
)
Public Function FindDetailRowTemplateControl(
visibleIndex As Integer,
id As String
) As Control
| 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.
|
| Type | Description |
|---|---|
| Control |
The control that the specified detail row’s template contains.
|
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)
}
If Not ASPxGridViewMaster.DetailRows.IsVisible(ASPxGridViewMaster.FocusedRowIndex) Then
ASPxGridViewMaster.DetailRows.ExpandRow(ASPxGridViewMaster.FocusedRowIndex)
End If
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();
}
}
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
master.DataBind()
master.DetailRows.ExpandRow(0)
End If
End Sub
Protected Sub detail_BeforePerformDataSelect(ByVal sender As Object, ByVal e As EventArgs)
detailData.SelectParameters("CategoryID").DefaultValue = (TryCast(sender, ASPxGridView)).GetMasterRowKeyValue().ToString()
End Sub
Protected Sub master_CustomCallback(ByVal sender As Object, ByVal e As ASPxGridViewCustomCallbackEventArgs)
Dim data As String() = e.Parameters.Split("|"c)
If data.Length = 3 AndAlso data(0) = "select" Then ProcessDetailSelection(Integer.Parse(data(1)), data(2) = "T")
End Sub
Private Sub ProcessDetailSelection(ByVal index As Integer, ByVal state As Boolean)
Dim detail As ASPxGridView = TryCast(master.FindDetailRowTemplateControl(index, "detail"), ASPxGridView)
If detail IsNot Nothing Then
If state Then
detail.Selection.SelectAll()
Else
detail.Selection.UnselectAll()
End If
End If
End Sub
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.
aspxgridview-edit-in-memory-dataset/CS/WebApp/Default.aspx.cs#L75
int i = MasterGridView.FindVisibleIndexByKeyValue(e.Keys[MasterGridView.KeyFieldName]);
Control c = MasterGridView.FindDetailRowTemplateControl(i, "ASPxGridView2");
e.Cancel = true;
aspxgridview-edit-in-memory-dataset/VB/WebApp/Default.aspx.vb#L87
Dim i As Integer = MasterGridView.FindVisibleIndexByKeyValue(e.Keys(MasterGridView.KeyFieldName))
Dim c As Control = MasterGridView.FindDetailRowTemplateControl(i, "ASPxGridView2")
e.Cancel = True
See Also