Skip to main content

How to: Bind a Pivot Grid to an OLAP Datasource

  • 3 minutes to read

If you have a cube on the OLAP server (Microsoft Analysis Services), you can view its data using the ASPxPivotGrid control. In this example, you will see how to specify connection settings to the server and create fields that represent specific measures and dimensions of the cube.

To bind the Pivot Grid control to an OLAP cube, follow the steps below.

  • Set ADOMD as a data provider using the ASPxPivotGrid.OLAPDataProvider property.
  • Specify connection settings to the server using the ASPxPivotGrid.OLAPConnectionStrings property. The connection string used in the example is shown below.

    OlapConnectionString="Provider=MSOLAP;Data Source=https://demos.devexpress.com/Services/OLAP/msmdpump.dll;Initial catalog=Adventure Works DW Standard Edition;Cube name=Adventure Works;Query Timeout=100;"

  • Create fields for all the measures and dimension in the bound OLAP cube, and moves these fields to the specified area, hiding them. To do it, use the ASPxPivotGrid.RetrieveFields method overload and set the field’s visibility to false.
  • Place some of the created fields within corresponding Pivot Grid Control areas and set the visibility of the fields to true, using the PivotGridFieldBase.Visible property.

Use the invoked Customization Form to specify the Pivot Grid control’s layout.

To learn more about OLAP Datasources, see OLAP Datasources.

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

namespace ASPxOlapRetrieveFieldsExample
{
    public partial class WebForm1 : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e)
        {

            // Specifies the OLAP connection settings.
            ASPxPivotGrid1.OLAPDataProvider = OLAPDataProvider.Adomd;
            ASPxPivotGrid1.OLAPConnectionString =
                @"Provider=MSOLAP;
                Data Source=https://demos.devexpress.com/Services/OLAP/msmdpump.dll; 
                Initial catalog=Adventure Works DW Standard Edition;
                Cube name=Adventure Works;
                Query Timeout=100;";

            // Retrieves fields.
            ASPxPivotGrid1.RetrieveFields(PivotArea.ColumnArea, false);

            // Adds some fields from the Field List to the specified area to create a report.
            ASPxPivotGrid1.Fields["[Customer].[Country].[Country]"].Area = PivotArea.RowArea;
            ASPxPivotGrid1.Fields["[Customer].[Country].[Country]"].Visible = true;
            ASPxPivotGrid1.Fields["[Customer].[City].[City]"].Area = PivotArea.RowArea;
            ASPxPivotGrid1.Fields["[Customer].[City].[City]"].Visible = true;
            ASPxPivotGrid1.Fields["[Date].[Fiscal].[Fiscal Year]"].Area = PivotArea.ColumnArea;
            ASPxPivotGrid1.Fields["[Date].[Fiscal].[Fiscal Year]"].Visible = true;
            ASPxPivotGrid1.Fields["[Measures].[Internet Sales Amount]"].Visible = true;

            // Sets the Customization Forms style to Excel2007 with additional capabilities.
            ASPxPivotGrid1.OptionsCustomization.CustomizationFormStyle = CustomizationFormStyle.Excel2007;

        }
    }
}