Skip to main content

How to: Save and Load Field Values' Collapsed States Together With Pivot Grid's Layout

  • 3 minutes to read

Field values' collapsed states can be restored only in the same layout they have been saved in. This example shows how to save and load a control's layout together with collapsed states to ensure that the states are loaded in the appropriate layout.

View Example

using System;
using System.IO;
using System.Web.UI;
using DevExpress.Utils;
using DevExpress.Web.ASPxPivotGrid;

namespace ASPxPivotGrid_SaveLoadCollapsedState {
    public partial class _Default : Page {
        protected void btnSave_Click(object sender, EventArgs e) {
            Session["Layout"] = ASPxPivotGrid1.SaveLayoutToString( PivotGridWebOptionsLayout.DefaultLayout );
            MemoryStream collapseStateStream = (MemoryStream)(Session["CollapseStateStream"]);
            if (collapseStateStream != null) {
            collapseStateStream = new MemoryStream();
            Session["CollapseStateStream"] = collapseStateStream;
        protected void btnLoad_Click(object sender, EventArgs e) {
            MemoryStream collapseStateStream = (MemoryStream)(Session["CollapseStateStream"]);
            string layout = (string)(Session["Layout"]);
            if (layout == null ||
                collapseStateStream == null) {
            ASPxPivotGrid1.LoadLayoutFromString(layout, PivotGridWebOptionsLayout.DefaultLayout  );
            collapseStateStream.Seek(0, SeekOrigin.Begin);
        protected void btnClear_Click(object sender, EventArgs e) {