Lesson 1 - Bind a Pivot Grid to an MDB Database
- 3 minutes to read
This tutorial shows how to add an ASPxPivotGrid to a new ASP.NET application, bind it to a database and create pivot grid fields mapped to appropriate fields from the database. In this example, a Northwind.mdb database is used to supply the ASPxPivotGrid with data.
Note
Download the completed project: Bind a Pivot Grid to an MDB Database (Runtime sample)
Watch the video: DevExpress ASP.NET Pivot Grid: Getting Started
- Steps 1-6. Create a New Project and Add ASPxPivotGrid to it
- Steps 7-13. Prepare a Data Source
- Steps 14-15. Create and Arrange Pivot Grid Fields
- Result
Steps 1-6. Create a New Project and Add ASPxPivotGrid to it
- Run MS Visual Studio.
Create a new project by selecting File | New | Project… In the invoked New Project dialog, select the Web section, and choose the DevExpress v18.2 Template Gallery.
In the DevExpress Template Gallery, go to the ASP.NET WEBFORMS category and select Empty Web Application.
In the DevExpress ASP.NET MVC Project Wizard, select Empty on the Choose Layout page.
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.
Drag and drop the ASPxPivotGrid control from the DX.18.2: Data & Analytics toolbox tab onto the page.
Steps 7-13. Prepare a Data Source
Right-click the App_Data folder and select Add | Existing Item… from the context menu. In the Add Existing Item dialog, locate the Northwind database file and click Add. You can find the database by the following path.
C:\Users\Public\Documents\DevExpress Demos 18.2\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.
In this window, open the Choose Data Source drop-down list and select New data source…
This will run the Data Source Configuration wizard.
On the first page, choose Database as the data source type and click OK.
On the next page, select the nwind.mdb database from the list and click Next.
On the next page, leave default settings and click Next.
On the Configure the Select Statement page, choose the database columns that you need to include in the data source. To do this, follow the steps below.
- Select Specify columns from a table or view.
- Select SalesPerson from the Name drop-down list.
Check the following columns:
- Country
- ProductName
- CategoryName
- Extended Price
- Sales Person
Click Next.
On the last page, you can optionally test the automatically generated query using the Test Query button.
To close the wizard, click Finish.
Steps 14-15. Create and Arrange Pivot Grid Fields
Click the smart tag icon and then click Designer…. This will invoke the ASPxPivotGrid Designer.
Click the Retrieve fields button, ensure that the Check All option is enabled, and then click OK to automatically create pivot grid fields for all data source columns.
The PivotGridControl will locate all the created fields in the Data Header Area.
Use drag-and-drop to move the fields between areas. Also, you can move the fields between the areas by using the Property pane and specifying their index within the areas (use the Area and AreaIndex properties).
Put 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.
Result
Run the project to see the result.