Back to Devexpress

ASPxPivotGrid.DataSource Property

aspnet-devexpress-dot-web-dot-aspxpivotgrid-dot-aspxpivotgrid-f73e9fb0.md

latest11.3 KB
Original Source

ASPxPivotGrid.DataSource Property

Gets or sets the object from which the data-bound control retrieves its list of data items.

Namespace : DevExpress.Web.ASPxPivotGrid

Assembly : DevExpress.Web.ASPxPivotGrid.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue(null)]
[PivotAPIMemberCategory(APICategory.RelationalSource)]
public override object DataSource { get; set; }
vb
<PivotAPIMemberCategory(APICategory.RelationalSource)>
<DefaultValue(Nothing)>
Public Overrides Property DataSource As Object

Property Value

TypeDefaultDescription
Objectnull

An object that represents the data source from which the data-bound control retrieves its data.

|

Remarks

Assigning a new value to the DataSource property causes a pivot grid update.

Note

The ASPxPivotGrid is also updated when the data source implementing the IBindingList interface raises the ListChanged event of the PropertyDescriptorAdded, PropertyDescriptorDeleted, PropertyDescriptorChanged or Reset type.

If some of the data source field values are custom objects (not numeric or string values), use the PivotGridOptionsData.CustomObjectConverter property to specify a serializer to be used to process them.

Note

The DataSource property cannot be set by themes or style sheet themes.

Example

This example demonstrates how to create an ASPxPivotGrid and bind it to data in code.

In this example, the ASPxPivotGrid and System.Web.UI.WebControls.AccessDataSource instances are created and initialized in code. Assign the AccessDataSource instance to the ASPxPivotGrid.DataSource property to bind the Pivot Grid to the created data source. Then call the ASPxPivotGrid.RetrieveFields method to generate DataSourceColumnBinding objects for each Pivot Grid field.

View Example

aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
    Inherits="ASPxPivotGrid_RuntimeDataBinding._Default" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server"/>
</body>
</html>
cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxPivotGrid;
using DevExpress.XtraPivotGrid;
using System.Linq;

namespace ASPxPivotGrid_RuntimeDataBinding {
    public partial class _Default : Page {
        //private AccessDataSource ds;
        private SqlDataSource ds;
        private ASPxPivotGrid ASPxPivotGrid1;
        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);

            // Initializes a data source.
            ds = new SqlDataSource("System.Data.OleDb","Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\nwind.mdb",
                "SELECT [CategoryName], [ProductName], [ProductSales], [ShippedDate] FROM [ProductReports]");

            // Initializes ASPxPivotGrid.
            ASPxPivotGrid1 = new ASPxPivotGrid();
            ASPxPivotGrid1.OptionsData.DataProcessingEngine = PivotDataProcessingEngine.Optimized;

            // Binds ASPxPivotGrid to the data source.
            ASPxPivotGrid1.DataSource = ds;

            // Places the Pivot Grid onto a page.
            form1.Controls.Add(ASPxPivotGrid1);

            if (ASPxPivotGrid1.Fields.Count != 0) 
                return;

            // Creates Pivot Grid fields for all data source columns.
            ASPxPivotGrid1.RetrieveFields();

            // Locates the Pivot Grid fields in appropriate areas.
            ASPxPivotGrid1.Fields["CategoryName"].Area = PivotArea.RowArea;
            ASPxPivotGrid1.Fields["ProductName"].Area = PivotArea.RowArea;
            ASPxPivotGrid1.Fields["ShippedDate"].Area = PivotArea.ColumnArea;
            ASPxPivotGrid1.Fields["ProductSales"].Area = PivotArea.DataArea;
            (ASPxPivotGrid1.Fields["ShippedDate"].DataBinding as DataSourceColumnBinding).GroupInterval = PivotGroupInterval.DateYear;

        }
    }
}
vb
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DevExpress.Web.ASPxPivotGrid
Imports DevExpress.XtraPivotGrid

Namespace ASPxPivotGrid_RuntimeDataBinding

    Public Partial Class _Default
        Inherits Page

        'private AccessDataSource ds;
        Private ds As SqlDataSource

        Private ASPxPivotGrid1 As ASPxPivotGrid

        Protected Overrides Sub OnLoad(ByVal e As EventArgs)
            MyBase.OnLoad(e)
            ' Initializes a data source.
            ds = New SqlDataSource("System.Data.OleDb", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\nwind.mdb", "SELECT [CategoryName], [ProductName], [ProductSales], [ShippedDate] FROM [ProductReports]")
            ' Initializes ASPxPivotGrid.
            ASPxPivotGrid1 = New ASPxPivotGrid()
            ASPxPivotGrid1.OptionsData.DataProcessingEngine = PivotDataProcessingEngine.Optimized
            ' Binds ASPxPivotGrid to the data source.
            ASPxPivotGrid1.DataSource = ds
            ' Places the Pivot Grid onto a page.
            form1.Controls.Add(ASPxPivotGrid1)
            If ASPxPivotGrid1.Fields.Count <> 0 Then Return
            ' Creates Pivot Grid fields for all data source columns.
            ASPxPivotGrid1.RetrieveFields()
            ' Locates the Pivot Grid fields in appropriate areas.
            ASPxPivotGrid1.Fields("CategoryName").Area = PivotArea.RowArea
            ASPxPivotGrid1.Fields("ProductName").Area = PivotArea.RowArea
            ASPxPivotGrid1.Fields("ShippedDate").Area = PivotArea.ColumnArea
            ASPxPivotGrid1.Fields("ProductSales").Area = PivotArea.DataArea
            TryCast(ASPxPivotGrid1.Fields("ShippedDate").DataBinding, DataSourceColumnBinding).GroupInterval = PivotGroupInterval.DateYear
        End Sub
    End Class
End Namespace

The following code snippets (auto-collected from DevExpress Examples) contain references to the DataSource property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

web-forms-pivot-grid-split-field-value-cells/CS/ASPxPivotGrid_SplittingCells/Default.aspx.cs#L15

csharp
}
    pivotGrid.DataSource = PivotHelper.GetDataTable();
}

web-forms-pivot-grid-hide-particular-rows-and-columns/CS/ASPxPivotGrid_HidingColumnsAndRows/Default.aspx.cs#L13

csharp
}
    pivotGrid.DataSource = PivotHelper.GetDataTable();
}

web-forms-pivot-grid-implement-editable-aspxpivotgrid/CS/Q240884/Default.aspx.cs#L12

csharp
protected void Page_Load(object sender, EventArgs e) {
    ASPxPivotGrid1.DataSource = CreatePivotData();
    ASPxPivotGrid1.DataBind();

web-forms-pivot-grid-bind-to-sql-data-source/CS/ASPxPivotGrid_RuntimeDataBinding/Default.aspx.cs#L25

csharp
// Binds ASPxPivotGrid to the data source.
ASPxPivotGrid1.DataSource = ds;

web-forms-pivot-grid-split-field-value-cells/VB/ASPxPivotGrid_SplittingCells/Default.aspx.vb#L19

vb
pivotGrid.DataSource = GetDataTable()
End Sub

web-forms-pivot-grid-hide-particular-rows-and-columns/VB/ASPxPivotGrid_HidingColumnsAndRows/Default.aspx.vb#L17

vb
pivotGrid.DataSource = GetDataTable()
End Sub

web-forms-pivot-grid-implement-editable-aspxpivotgrid/VB/Q240884/Default.aspx.vb#L14

vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    ASPxPivotGrid1.DataSource = CreatePivotData()
    ASPxPivotGrid1.DataBind()

web-forms-pivot-grid-bind-to-sql-data-source/VB/ASPxPivotGrid_RuntimeDataBinding/Default.aspx.vb#L25

vb
' Binds ASPxPivotGrid to the data source.
ASPxPivotGrid1.DataSource = ds
' Places the Pivot Grid onto a page.

See Also

DataSourceID

ASPxPivotGrid Class

ASPxPivotGrid Members

DevExpress.Web.ASPxPivotGrid Namespace