The requested page is not available for the requested platform. You are viewing the content for Default platform.

Lesson 1 - Bind a Pivot Grid to an MDB Database

  • 3 min 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.

Steps 1-6. Create a New Project and Add ASPxPivotGrid to it

  1. Run MS Visual Studio.
  2. Create a new project by selecting File | New | Project… In the invoked New Project dialog, select the Web section, and choose the DevExpress v19.2 Template Gallery.

    Lesson5_NewProject_DXTemplateGallery

  3. In the DevExpress Template Gallery, go to the ASP.NET WEBFORMS category and select Empty Web Application.

    DXTemplateGallery_AspNet_EmptyWebApp

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

    AspProjectWizard_ChooseLayout

    Click Create Project.

  5. 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.

    ASPxPivotGrid_L1_AddWebForm

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

    GettingStarted_L1_Toolbox

Steps 7-13. Prepare a Data Source

  1. 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 19.2\Components\Data\nwind.mdb

  2. 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

    In this window, open the Choose Data Source drop-down list and select New data source...

    GettingStarted_L1_NewDataSource

    This will run the Data Source Configuration wizard.

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

    ASPxPivotGrid_L1_SelectSqlDatabase

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

    ASPxPivotGrid_L1_DataSource_SelectNwindDatabase

  5. On the next page, leave default settings and click Next.

    ASPxPivotGrid_L1_DataSource_SaveConnectionString

  6. 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.

    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

    ASPxPivotGrid_L1_DataSource_SelectColumns

    Click Next.

  7. On the last page, you can optionally test the automatically generated query using the Test Query button.

    ASPxPivotGrid_L1_DataSource_Finish

    To close the wizard, click Finish.

Steps 14-15. Create and Arrange Pivot Grid Fields

  1. Click the smart tag icon and then click Designer.... This will 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 automatically create pivot grid fields for all data source columns.

    GettingStarted_L1_RetrieveFields_Click

    The PivotGridControl will locate all the created fields in the Data Header Area.

  2. 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.

    GettingStarted_L1_ArrangeFields

Result

  1. Run the project to see the result.

    GettingStarted_L1_Result

See Also