The demo shows how the
RadPivotGrid control can be described and used programmatically. When generating a
RadPivotGrid in the Page_Init event handler, PivotGrid fields need to be added to the Fields collection of the control after their attributes are set. No ViewState is required for PivotGrid structure to be persisted as it is recreated on each page initialization:
C#
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
RadPivotGrid pivotGrid = new RadPivotGrid();
...
PivotGridRowField rowField = new PivotGridRowField();
rowField.DataField = "TransportType";
rowField.UniqueName = "TransportType";
pivotGrid.Fields.Add(rowField);
rowField = new PivotGridRowField();
rowField.DataField = "FuelCapacity";
rowField.UniqueName = "FuelCapacity";
pivotGrid.Fields.Add(rowField);
...
ContentPanel.Controls.Add(pivotGrid);
}
VB
Protected Overrides Sub OnInit(e As EventArgs)
MyBase.OnInit(e)
Dim pivotGrid As New RadPivotGrid()
...
Dim rowField As New PivotGridRowField()
rowField.DataField = "TransportType"
rowField.UniqueName = "TransportType"
pivotGrid.Fields.Add(rowField)
rowField = New PivotGridRowField()
rowField.DataField = "FuelCapacity"
rowField.UniqueName = "FuelCapacity"
pivotGrid.Fields.Add(rowField)
...
ContentPanel.Controls.Add(pivotGrid)
End Sub