ASPxPivotGrid.RetrieveFields(PivotArea, Boolean) Method
Creates PivotGridField objects for all the fields in the bound data source, and moves the fields to the specified area, making them visible or hidden.
Namespace: DevExpress.Web.ASPxPivotGrid
Assembly: DevExpress.Web.ASPxPivotGrid.v24.2.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
area | PivotArea | A PivotArea value that specifies the area to which the created fields are moved. |
visible | Boolean | true if the created fields are made visible; otherwise, false. |
Remarks
This method clears the field collection and adds new PivotGridField objects to the collection for all columns in the control’s bound data source. This overload moves the created fields to the area according to the area parameter. The visible parameter specifies whether these fields are made visible or hidden.
The RetrieveFields
method generates DataSourceColumnBinding objects for each Pivot Grid field in OLAP, Server, and Optimized modes. The Pivot Grid fields obtain their values from columns in the data source. The DataSourceColumnBindingBase.ColumnName property is set to the name of the data source column. The created fields are made visible and displayed within the Filter Header Area.
Use the ASPxPivotGrid.Fields property to add or remove fields. For instance, you can add a calculated field to a collection that contains arbitrary data in the Pivot Grid control. Refer to the following topic for more information about calculated fields: Bind Pivot Grid Fields to Calculated Expressions.
Specify a value of the PivotGridField.ID property for each field when you create Pivot Grid fields. You can use this value to determine fields in a stored layout.
Refer to the following topic for more information about Pivot Grid Fields: Pivot Grid Fields.
Example
The following example shows how to create and bind the Pivot Grid control to data in code. Call the RetrieveFields
method to generate DataSourceColumnBinding objects for each Pivot Grid field in OLAP, Server, and Optimized modes.
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;
}
}
}