New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Programmatic Creation

There are many cases where you will need to create the RadPivotGrid control dynamically. In some scenarios you might want to declare it statically on the page and configure it with server-side code orbuild it entirely in code-behind. Both cases have a few requirements you should follow:

  • Create the RadPivotGrid entirely in code-behind - here you should place all the code in the Page_Init event handler. Note that the columns have to beadded to the Columns collection after their properties are set.

  • Add the RadPivotGrid declaration statically in the page mark-up and configure itserver-side - configuration is to be done in the Page_Load eventhandler and only on initial load (with Not IsPostBack condition) to avoid adding the same structuretwice. In contrast to the scenario above, columns have to be added to the Columns collection before their properties are set.

The samples bellow illustrate both approaches:

Create the RadPivotGrid entirely in code-behind on Page_Init

ASPNET
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadAjaxPanel ID="radAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">   
<h3>RadTreeList created entirely in code-behind on Page_Init</h3>
<asp:Panel ID="ContentPanel" runat="server">
</asp:Panel>
</telerik:RadAjaxPanel>

Statically declared RadPivotGrid and configured on Page_Load

ASPNET
<telerik:RadScriptManager ID="RadScriptManager1" runat="server" />    
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadAjaxPanel ID="radAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
 <h3>RadTreeList declared statically with structure defined on Page_Load</h3>
    <telerik:RadPivotGrid RenderMode="Lightweight" runat="server" ID="RadPivotGrid1"></telerik:RadPivotGrid>
</telerik:RadAjaxPanel>