Skip to main content
A newer version of this page is available. .
Tab

ASPxGridView.CollapseAll() Method

Collapses all group rows.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v18.2.dll

Declaration

public void CollapseAll()

Remarks

To collapse the specified group row, use the ASPxGridView.CollapseRow method. To expand all group rows, use the ASPxGridView.ExpandAll method.

Example

This example shows how to expand various groups of rows in ASPxGridView. Information about a row’s state is saved by clicking the ‘Save’ button. To restore saved rows’ state, click the ‘Restore’ button.

Visible indexes of the stored groups are shown in the text field below.

MVC version: T360561 - GridView - How to restore the expanded group rows state after a page is refreshed

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 System.Collections.Generic;

public partial class _Default : System.Web.UI.Page
{
    protected void btnSave_Click(object sender, EventArgs e) {
        List<int> states = new List<int>();

        for (Int32 i = 0; i < grid.VisibleRowCount; i++) {
            if (grid.IsGroupRow(i) && grid.IsRowExpanded(i))
                states.Add(i);
        }
        Session["expandedRows"] = states;
    }
    protected void btnLoad_Click(object sender, EventArgs e) {
        List<int> states = Session["expandedRows"] as List<int> ;
        if (states == null)
            return;

        grid.CollapseAll();
        foreach (int index in states)
            grid.ExpandRow(index);
    }
}
See Also