ASPxGridView.ExpandAll() Method
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v18.2.dll
Declaration
To expand the specified group row, use the ASPxGridView.ExpandRow method. To collapse all group rows, use the ASPxGridView.CollapseAll method.
Example
To expand all the nested detail grids, define a session variable. When the expand action is activated, set it to True, and handle the detail grid's DataBound event. In the event handler check if this variable is set to True, and expand this grid's details using the ASPxGridView.DetailRows.ExpandAllRows method. In the Page.Load event handler, set this variable to False to prevent automatic detail expanding on the next callback or postback.
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxGridView;
namespace WebApplication79
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["expandAll"] = false;
}
protected void ASPxGridView3_BeforePerformDataSelect(object sender, EventArgs e)
{
Session["ProductID"] = ((ASPxGridView)sender).GetMasterRowKeyValue();
}
protected void ASPxGridView2_BeforePerformDataSelect(object sender, EventArgs e)
{
Session["CategoryID"] = ((ASPxGridView)sender).GetMasterRowKeyValue();
}
protected void ASPxButton1_Click(object sender, EventArgs e)
{
Session["expandAll"] = true;
ASPxGridView1.DetailRows.ExpandAllRows();
}
protected void ASPxGridView2_DataBound(object sender, EventArgs e)
{
if (Convert.ToBoolean(Session["expandAll"]))
((ASPxGridView)sender).DetailRows.ExpandAllRows();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication79._Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v8.2, Version=8.2.4.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v8.2, Version=8.2.4.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="CategoryID">
<Templates>
<DetailRow>
<dxwgv:ASPxGridView ID="ASPxGridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource2" KeyFieldName="ProductID" OnBeforePerformDataSelect="ASPxGridView2_BeforePerformDataSelect"
OnDataBound="ASPxGridView2_DataBound">
<Templates>
<DetailRow>
<dxwgv:ASPxGridView ID="ASPxGridView3" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource3" KeyFieldName="OrderID" OnBeforePerformDataSelect="ASPxGridView3_BeforePerformDataSelect">
<Columns>
<dxwgv:GridViewDataTextColumn FieldName="OrderID" ReadOnly="True" VisibleIndex="0">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="1">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="2">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="Quantity" VisibleIndex="3">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="Discount" VisibleIndex="4">
</dxwgv:GridViewDataTextColumn>
</Columns>
<SettingsDetail IsDetailGrid="True" />
</dxwgv:ASPxGridView>
</DetailRow>
</Templates>
<Columns>
<dxwgv:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="1">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="SupplierID" VisibleIndex="2">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="CategoryID" VisibleIndex="3">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="QuantityPerUnit" VisibleIndex="4">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="5">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="UnitsInStock" VisibleIndex="6">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="UnitsOnOrder" VisibleIndex="7">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="ReorderLevel" VisibleIndex="8">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataCheckColumn FieldName="Discontinued" VisibleIndex="9">
</dxwgv:GridViewDataCheckColumn>
<dxwgv:GridViewDataTextColumn FieldName="EAN13" VisibleIndex="10">
</dxwgv:GridViewDataTextColumn>
</Columns>
<SettingsDetail IsDetailGrid="True" ShowDetailRow="True" />
</dxwgv:ASPxGridView>
</DetailRow>
</Templates>
<Columns>
<dxwgv:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="Description" VisibleIndex="2">
</dxwgv:GridViewDataTextColumn>
</Columns>
<SettingsDetail ShowDetailRow="True" />
</dxwgv:ASPxGridView>
<dxe:ASPxButton ID="ASPxButton1" runat="server" Text="Expand All Deep" OnClick="ASPxButton1_Click">
</dxe:ASPxButton>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:nwindConnectionString2 %>" ProviderName="<%$ ConnectionStrings:nwindConnectionString2.ProviderName %>"
SelectCommand="SELECT * FROM [Categories]"></asp:SqlDataSource>
</div>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:nwindConnectionString2 %>" ProviderName="<%$ ConnectionStrings:nwindConnectionString2.ProviderName %>"
SelectCommand="SELECT * FROM [Products] WHERE ([CategoryID] = @CategoryID)">
<SelectParameters>
<asp:SessionParameter Name="CategoryID" SessionField="CategoryID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:nwindConnectionString2 %>" ProviderName="<%$ ConnectionStrings:nwindConnectionString2.ProviderName %>"
SelectCommand="SELECT * FROM [Order Details] WHERE ([ProductID] = @ProductID)">
<SelectParameters>
<asp:SessionParameter Name="ProductID" SessionField="ProductID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="WebApplication79._Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v8.2, Version=8.2.4.0, Culture=neutral, PublicKeyToken=9B171C9FD64DA1D1"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v8.2, Version=8.2.4.0, Culture=neutral, PublicKeyToken=9B171C9FD64DA1D1"
Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="CategoryID">
<Templates>
<DetailRow>
<dxwgv:ASPxGridView ID="ASPxGridView2" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource2" KeyFieldName="ProductID" OnBeforePerformDataSelect="ASPxGridView2_BeforePerformDataSelect"
OnDataBound="ASPxGridView2_DataBound">
<Templates>
<DetailRow>
<dxwgv:ASPxGridView ID="ASPxGridView3" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource3" KeyFieldName="OrderID" OnBeforePerformDataSelect="ASPxGridView3_BeforePerformDataSelect">
<Columns>
<dxwgv:GridViewDataTextColumn FieldName="OrderID" ReadOnly="True" VisibleIndex="0">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="1">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="2">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="Quantity" VisibleIndex="3">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="Discount" VisibleIndex="4">
</dxwgv:GridViewDataTextColumn>
</Columns>
<SettingsDetail IsDetailGrid="True" />
</dxwgv:ASPxGridView>
</DetailRow>
</Templates>
<Columns>
<dxwgv:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="1">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="SupplierID" VisibleIndex="2">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="CategoryID" VisibleIndex="3">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="QuantityPerUnit" VisibleIndex="4">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="5">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="UnitsInStock" VisibleIndex="6">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="UnitsOnOrder" VisibleIndex="7">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="ReorderLevel" VisibleIndex="8">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataCheckColumn FieldName="Discontinued" VisibleIndex="9">
</dxwgv:GridViewDataCheckColumn>
<dxwgv:GridViewDataTextColumn FieldName="EAN13" VisibleIndex="10">
</dxwgv:GridViewDataTextColumn>
</Columns>
<SettingsDetail IsDetailGrid="True" ShowDetailRow="True" />
</dxwgv:ASPxGridView>
</DetailRow>
</Templates>
<Columns>
<dxwgv:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataTextColumn FieldName="Description" VisibleIndex="2">
</dxwgv:GridViewDataTextColumn>
</Columns>
<SettingsDetail ShowDetailRow="True" />
</dxwgv:ASPxGridView>
<dxe:ASPxButton ID="ASPxButton1" runat="server" Text="Expand All Deep" OnClick="ASPxButton1_Click">
</dxe:ASPxButton>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:nwindConnectionString2 %>" ProviderName="<%$ ConnectionStrings:nwindConnectionString2.ProviderName %>"
SelectCommand="SELECT * FROM [Categories]"></asp:SqlDataSource>
</div>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:nwindConnectionString2 %>" ProviderName="<%$ ConnectionStrings:nwindConnectionString2.ProviderName %>"
SelectCommand="SELECT * FROM [Products] WHERE ([CategoryID] = @CategoryID)">
<SelectParameters>
<asp:SessionParameter Name="CategoryID" SessionField="CategoryID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:nwindConnectionString2 %>" ProviderName="<%$ ConnectionStrings:nwindConnectionString2.ProviderName %>"
SelectCommand="SELECT * FROM [Order Details] WHERE ([ProductID] = @ProductID)">
<SelectParameters>
<asp:SessionParameter Name="ProductID" SessionField="ProductID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports DevExpress.Web.ASPxGridView
Namespace WebApplication79
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Session("expandAll") = False
End Sub
Protected Sub ASPxGridView3_BeforePerformDataSelect(ByVal sender As Object, ByVal e As EventArgs)
Session("ProductID") = (CType(sender, ASPxGridView)).GetMasterRowKeyValue()
End Sub
Protected Sub ASPxGridView2_BeforePerformDataSelect(ByVal sender As Object, ByVal e As EventArgs)
Session("CategoryID") = (CType(sender, ASPxGridView)).GetMasterRowKeyValue()
End Sub
Protected Sub ASPxButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
Session("expandAll") = True
ASPxGridView1.DetailRows.ExpandAllRows()
End Sub
Protected Sub ASPxGridView2_DataBound(ByVal sender As Object, ByVal e As EventArgs)
If Convert.ToBoolean(Session("expandAll")) Then
CType(sender, ASPxGridView).DetailRows.ExpandAllRows()
End If
End Sub
End Class
End Namespace
The following code snippets (auto-collected from DevExpress Examples) contain references to the ExpandAll() 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