Example E1872
Visible to All Users

How to Customize Cell Styles via Event

Files to look at:

The following example shows how to customize the appearance of specific cells via the ASPxPivotGrid.CustomCellStyle event.

In this example, custom style settings (the orange background and bold font) are applied to a cell if it meets the following conditions:

-- It belongs to the "Quantity" data field.
-- It's not displayed within total rows or columns.
-- Its value is greater than 50.

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

ASPxPivotGrid_CustCellsStylesViaEvents/Default.aspx
ASPx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CustomizeCellsAppearanceViaEvents._Default" %> <%@ Register Assembly="DevExpress.Web.ASPxPivotGrid.v24.2, Version=24.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPivotGrid" TagPrefix="dx" %> <!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></title> </head> <body> <form id="form1" runat="server"> <div> <dx:ASPxPivotGrid ID="ASPxPivotGrid1" runat="server" DataSourceID="SqlDataSource1" OnCustomCellStyle="CustomCellStyle" ClientIDMode="AutoID" IsMaterialDesign="False"> <Fields> <dx:PivotGridField ID="fieldCity" Area="ColumnArea" AreaIndex="2"> <DataBindingSerializable> <dx:DataSourceColumnBinding ColumnName="City" /> </DataBindingSerializable> </dx:PivotGridField> <dx:PivotGridField ID="fieldRegion" Area="ColumnArea" AreaIndex="1"> <DataBindingSerializable> <dx:DataSourceColumnBinding ColumnName="Region" /> </DataBindingSerializable> </dx:PivotGridField> <dx:PivotGridField ID="fieldCountry" Area="ColumnArea" AreaIndex="0"> <DataBindingSerializable> <dx:DataSourceColumnBinding ColumnName="Country" /> </DataBindingSerializable> </dx:PivotGridField> <dx:PivotGridField ID="fieldUnitPrice" Area="DataArea" AreaIndex="0"> <DataBindingSerializable> <dx:DataSourceColumnBinding ColumnName="UnitPrice" /> </DataBindingSerializable> </dx:PivotGridField> <dx:PivotGridField ID="fieldQuantity" Area="DataArea" AreaIndex="1"> <DataBindingSerializable> <dx:DataSourceColumnBinding ColumnName="Quantity" /> </DataBindingSerializable> </dx:PivotGridField> <dx:PivotGridField ID="fieldProductName" Area="RowArea" AreaIndex="0"> <DataBindingSerializable> <dx:DataSourceColumnBinding ColumnName="ProductName" /> </DataBindingSerializable> </dx:PivotGridField> </Fields> <OptionsData DataProcessingEngine="Optimized" /> </dx:ASPxPivotGrid> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT [City], [Region], [Country], [UnitPrice], [Quantity], [ProductName] FROM [Invoices]"></asp:SqlDataSource> </div> </form> </body> </html>
ASPxPivotGrid_CustCellsStylesViaEvents/Default.aspx.cs(vb)
C#
using System; using System.Drawing; using DevExpress.Web.ASPxPivotGrid; using DevExpress.XtraPivotGrid; namespace CustomizeCellsAppearanceViaEvents { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void CustomCellStyle(object sender, PivotCustomCellStyleEventArgs e) { if (e.ColumnValueType != PivotGridValueType.Value || e.RowValueType != PivotGridValueType.Value) return; if (Convert.ToInt32(e.Value) > 50 && e.DataField == fieldQuantity) { e.CellStyle.BackColor = Color.Orange; e.CellStyle.Font.Bold = true; } } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.