New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Custom Serialization Provider

empty
QuantityYearQuarter
ProductName
19971997 Total 19981998 TotalGrand Total
Quarter 1Quarter 2Quarter 3Quarter 4Quarter 1Quarter 2Quarter 3Quarter 4
36.0028.5716.5060.0029.2812.0041.6713.259.0019.7325.66
22.7525.6724.0022.4423.8418.3338.3351.5015.0030.3025.69
25.1738.3317.0035.7131.6721.7539.00100.0022.0030.0030.90
22.83 15.0028.7523.5017.6718.3325.006.0015.1019.68
33.1711.5012.0012.5021.77 19.7544.3330.0030.2525.00
22.6524.8825.6024.0724.2925.5023.6325.6721.5223.9824.17
Alice Mutton
Boston Crab Meat
Camembert Pierrot
Carnarvon Tigers
Chartreuse verte
Grand Total
Page 1 of 13

In this example you can see how to preserve the state of RadPivotGrid using a custom serializer provider. The custom serializer provider implements IStateSerializer interface containing Serialize, Deserialize and DeserializeCollection methods which are used by the PersistenceManager to load/save the state. To demonstrates this functionality we construct a BinaryFormatter and use it to serialize/deserialize the RadControlState to the MemoryStream.

  • DefaultCS.aspx
  • BinarySerializerCS.cs
    • BinarySerializerCS.cs
    • DefaultCS.aspx.cs
  • styles.css
<%@ Page Title="" Language="C#"  AutoEventWireup="true"
    CodeFile="DefaultCS.aspx.cs" Inherits="PersistenceFramework_Examples_CustomSerializerProvider_DefaultCS" %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
    <link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <telerik:RadPersistenceManager ID="RadPersistenceManager1" runat="server" StorageProviderKey="MyProviderKey">
        <PersistenceSettings>
            <telerik:PersistenceSetting ControlID="RadPivotGrid1" />
        </PersistenceSettings>
    </telerik:RadPersistenceManager>
    <div class="demo-container">
        <div class="demo-settings">
            <telerik:RadButton RenderMode="Lightweight" ID="SaveButton" Text="Save State" runat="server" OnClick="SaveButton_Click">
            </telerik:RadButton>
            <telerik:RadButton RenderMode="Lightweight" ID="LoadButton" Text="Load State" runat="server" OnClick="LoadButton_Click">
            </telerik:RadButton>
            <telerik:RadButton RenderMode="Lightweight" ID="ResetButton" Text="Reset State" runat="server" OnClick="ResetButton_Click">
            </telerik:RadButton>
        </div>
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
            <telerik:RadPivotGrid RenderMode="Lightweight" runat="server" ID="RadPivotGrid1" AllowPaging="true" PageSize="5"
                OnNeedDataSource="RadPivotGrid1_NeedDataSource" Width="100%" AllowSorting="true"
                AllowFiltering="false" ShowFilterHeaderZone="false">
                <PagerStyle Mode="Slider" AlwaysVisible="true"></PagerStyle>
                <Fields>
                    <telerik:PivotGridColumnField DataField="Year" Caption="Year" UniqueName="Discount">
                    </telerik:PivotGridColumnField>
                    <telerik:PivotGridColumnField DataField="Quarter" Caption="Quarter" DataFormatString="Quarter {0}" UniqueName="UnitPrice">
                    </telerik:PivotGridColumnField>
                    <telerik:PivotGridAggregateField DataField="Quantity" Caption="Quantity" UniqueName="Quantity"
                        Aggregate="Average" DataFormatString="{0:F2}">
                    </telerik:PivotGridAggregateField>
                    <telerik:PivotGridRowField DataField="ProductName" Caption="ProductName" UniqueName="ProductName">
                    </telerik:PivotGridRowField>
                    <telerik:PivotGridRowField IsHidden="true" DataField="TotalPrice" Caption="OrderID"
                        UniqueName="OrderID" DataFormatString="{0:F2}">
                    </telerik:PivotGridRowField>
                </Fields>
            </telerik:RadPivotGrid>
        </telerik:RadAjaxPanel>
    </div>

    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance