aspnet-115603-components-pivot-grid-examples-binding-to-data-how-to-bind-a-pivot-grid-to-an-olap-datasource.md
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.
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;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ASPxOlapRetrieveFieldsExample.WebForm1" %>
<%@ Register Assembly="DevExpress.Web.ASPxPivotGrid.v15.2, Version=15.2.5.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" ClientIDMode="AutoID"
EnableTheming="True"
Theme="Metropolis">
</dx:ASPxPivotGrid>
<dx:ASPxPivotCustomizationControl ID="ASPxPivotCustomizationControl1"
runat="server" ASPxPivotGridID="ASPxPivotGrid1" Height="388px" Width="250px">
</dx:ASPxPivotCustomizationControl>
</div>
</form>
</body>
</html>
<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="WebForm1.aspx.vb" Inherits="ASPxOlapRetrieveFieldsExample.WebForm1" %>
<%@ Register Assembly="DevExpress.Web.ASPxPivotGrid.v15.2, Version=15.2.5.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" ClientIDMode="AutoID"
EnableTheming="True"
Theme="Metropolis">
</dx:ASPxPivotGrid>
<dx:ASPxPivotCustomizationControl ID="ASPxPivotCustomizationControl1"
runat="server" ASPxPivotGridID="ASPxPivotGrid1" Height="388px" Width="250px">
</dx:ASPxPivotCustomizationControl>
</div>
</form>
</body>
</html>
Imports System
Imports DevExpress.XtraPivotGrid
Imports DevExpress.XtraPivotGrid.Customization
Imports DevExpress.Web.ASPxPivotGrid
Namespace ASPxOlapRetrieveFieldsExample
Partial Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Specifies the OLAP connection settings.
ASPxPivotGrid1.OLAPDataProvider = OLAPDataProvider.Adomd
ASPxPivotGrid1.OLAPConnectionString = "Provider=MSOLAP;" & ControlChars.CrLf & _
" Data Source=https://demos.devexpress.com/Services/OLAP/msmdpump.dll; " & ControlChars.CrLf & _
" Initial catalog=Adventure Works DW Standard Edition;" & ControlChars.CrLf & _
" Cube name=Adventure Works;" & ControlChars.CrLf & _
" 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
End Sub
End Class
End Namespace