Skip to main content

How to: Format Cells via Events

  • 2 minutes to read

The following example shows how to provide custom text for the ASPxPivotGrid’s cells by handling the ASPxPivotGrid.CustomCellDisplayText event.

In this example, if a Grand Total value is less than 50 000, ASPxPivotGrid displays the Low value instead. If the value exceeds 100 000, High is displayed; otherwise, Middle.

using System;
using System.Web.UI;
using DevExpress.Web.ASPxPivotGrid;
using DevExpress.XtraPivotGrid;

namespace FormattingViaEvents {
    public partial class _Default : Page {
        protected void Page_Load(object sender, EventArgs e) {
        }
        protected void CustomCellDisplayText(object sender, PivotCellDisplayTextEventArgs e) {
            if (e.RowValueType != PivotGridValueType.GrandTotal ||
                e.ColumnValueType == PivotGridValueType.GrandTotal) return;
            if (Convert.ToSingle(e.Value) < 50000)
                e.DisplayText = "Low";
            else if (Convert.ToSingle(e.Value) > 100000)
                e.DisplayText = "High";
            else
                e.DisplayText = "Middle";
        }
    }
}