Skip to main content

Lesson 1 - Bind a Pivot Grid to an MDB Database

  • 3 minutes to read

This tutorial shows how to add DevExpress.Web.ASPxPivotGrid to a new ASP.NET application, bind the Pivot Grid to a database, and create the control’s fields mapped to the appropriate fields from the database. The Northwind.mdb database is used in this example to supply ASPxPivotGrid with data.

Create a New Project and Add ASPxPivotGrid

Run Microsoft Visual Studio.

Click Create a new project and select DevExpress v24.1 Web App Template Gallery.

Create a new project in Visual Studio

Select Web Application and click Run Wizard.

Create a new Web Application in DevExpress Template Gallery

In the DevExpress ASP.NET Project Wizard, select Empty on the Choose Layout page.

The Project Wizard

Click Create Project.

Right-click the project in the Solution Explorer and select Add | Web Form from the context menu. In the invoked dialog, leave the default item name and click OK.

Add WebForm to the project

Drag and drop the ASPxPivotGrid control from the DX.24.1 Data & Analytics toolbox tab onto the page.

Drop the Pivot Grid from the Toolbox

Prepare a Data Source

Right-click the App_Data folder in your project and select Add | Existing Item… from the context menu. In the Add Existing Item dialog, locate the Northwind database file and click Add. Use the following path to find the database:

C:\Users\Public\Documents\DevExpress Demos 24.1\Components\Data\nwind.mdb

Click the smart tag icon displayed in the top-right corner of the Pivot Grid to invoke the ASPxPivotGrid Tasks popup window.

GettingStarted_L1_SmartTag

Open the Choose Data Source drop-down list and select New data source… to run the Data Source Configuration wizard.

Create a new data source

On the first page, choose Database as the data source type and click OK.

Select the data source type

On the next page, select the nwind.mdb database from the list and click Next.

Choose data connection

Leave the default settings and click Next.

Specify a connection string

On the Configure the Select Statement page, choose the database columns that you need to include in the data source and click Next.

  1. Select Specify columns from a table or view.
  2. Select SalesPerson from the Name drop-down list.
  3. Check the following columns:

    • Country
    • ProductName
    • CategoryName
    • Extended Price
    • Sales Person

Select data source columns to include them in the query

You can optionally test the automatically generated query. For this, click the Test Query button.

Finish data source settings

Click Finish to close the wizard.

Create and Arrange Pivot Grid Fields

Click the smart tag icon and then click Designer… to invoke the ASPxPivotGrid Designer.

ASPxPivotGrid_L1_RunDesigner

Click the Retrieve fields button, ensure that the Check All option is enabled, and then click OK to create Pivot Grid fields automatically for all data source columns.

GettingStarted_L1_RetrieveFields_Click

The PivotGridControl locates all created fields in the Data Header Area.

Drag-and-drop fields to move them between areas. You can also specify the field’s location and position between areas in the Property pane (for this, use the Area and AreaIndex properties).

Place the CategoryName and ProductName fields (in the given order) into the Row Header Area, the Country and Sales_Person fields into the Column Header Area, and the Extended_Price field into the Data Header Area.

GettingStarted_L1_ArrangeFields

Result

Run the project to see the result.

GettingStarted_L1_Result

See Also