Assigning a new value to the DataSource property causes a pivot grid update.
NoteThe ASPxPivotGrid is also updated when the data source implementing the System.ComponentModel.IBindingList interface raises the System.ComponentModel.IBindingList.ListChanged event of the System.ComponentModel.ListChangedType.PropertyDescriptorAdded, System.ComponentModel.ListChangedType.PropertyDescriptorDeleted, System.ComponentModel.ListChangedType.PropertyDescriptorChanged or System.ComponentModel.ListChangedType.Reset type.
If some of the data source field values are custom objects (not numeric or string values), use the DevExpress.XtraPivotGrid.PivotGridOptionsData.CustomObjectConverter property to specify a serializer to be used to process them.
NoteThe DataSource property cannot be set by themes or style sheet themes.
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. The Pivot Grid is bound to data by assigning the AccessDataSource instance to the DataSource property. Then, the RetrieveFields method is used to create pivot grid fields for all data source fields.
ASP.NET:Default.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>
|
C#:Default.aspx.cs |
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxPivotGrid;
using DevExpress.XtraPivotGrid;
namespace ASPxPivotGrid_RuntimeDataBinding {
public partial class _Default : Page {
private AccessDataSource ds;
private ASPxPivotGrid ASPxPivotGrid1;
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
ds = new AccessDataSource("~/nwind.mdb", "SELECT [CategoryName]," +
"[ProductName], [ProductSales], [ShippedDate] FROM [ProductReports]");
ASPxPivotGrid1 = new ASPxPivotGrid();
ASPxPivotGrid1.DataSource = ds;
form1.Controls.Add(ASPxPivotGrid1);
if (ASPxPivotGrid1.Fields.Count != 0)
return;
ASPxPivotGrid1.RetrieveFields();
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"].GroupInterval = PivotGroupInterval.DateYear;
}
}
}
|
VB:Default.aspx.vb |
Imports Microsoft.VisualBasic
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DevExpress.Web.ASPxPivotGrid
Imports DevExpress.XtraPivotGrid
Namespace ASPxPivotGrid_RuntimeDataBinding
Partial Public Class _Default
Inherits Page
Private ds As AccessDataSource
Private ASPxPivotGrid1 As ASPxPivotGrid
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
ds = New AccessDataSource("~/nwind.mdb", "SELECT [CategoryName]," & _
"[ProductName], [ProductSales], [ShippedDate] FROM [ProductReports]")
ASPxPivotGrid1 = New ASPxPivotGrid()
ASPxPivotGrid1.DataSource = ds
form1.Controls.Add(ASPxPivotGrid1)
If ASPxPivotGrid1.Fields.Count <> 0 Then
Return
End If
ASPxPivotGrid1.RetrieveFields()
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").GroupInterval = PivotGroupInterval.DateYear
End Sub
End Class
End Namespace
|