This example presents how to create
RadPivotGrid control and its structure dynamically on
Page_Load event. When the control is declared statically and configured on
Page_Load event, you should first add the fields to the
RadPivotGrid Fields collection and after that set their properties. Also check the condition
(Not IsPostBack) to avoid adding the same structure objects to the PivotGrid control twice.
<telerik:RadPivotGrid runat="server" id="RadPivotGrid1"></telerik:RadPivotGrid>
C#
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!IsPostBack)
{
...
PivotGridRowField rowField = new PivotGridRowField();
RadPivotGrid1.Fields.Add(rowField);
rowField.DataField = "TransportType";
rowField.UniqueName = "TransportType";
rowField = new PivotGridRowField();
RadPivotGrid1.Fields.Add(rowField);
rowField.DataField = "Company";
rowField.UniqueName = "Company";
...
}
}
VB
Protected Overrides Sub OnLoad(e As EventArgs) MyBase.OnLoad(e)
If Not IsPostBack Then
...
Dim rowField As New PivotGridRowField()
RadPivotGrid1.Fields.Add(rowField)
rowField.DataField = "TransportType"
rowField.UniqueName = "TransportType"
rowField = New PivotGridRowField()
RadPivotGrid1.Fields.Add(rowField)
rowField.DataField = "Company"
rowField.UniqueName = "Company"
...
End If
End Sub