Hi,
I have added RadPivotGrid to my vb.net page and RadPersistenceManager . I managed to save and load the user current state with the following:
RadPersistenceManager1.StorageProviderKey = fileId
RadPersistenceManager1.SaveState()
However, I need to get the XML and save the XML in the db and then load the xml when user clicks the load button.
How do I load and save XML from database?
Thanks
4 Answers, 1 is accepted
You need a custom storage provider. I would recommend that you examine our online demo that shows how to implement a cookie storage provider.
PersistenceFramework - Custom Storage Provider
Documentation: Custom Storage Provider
Regards,
Daniel
Telerik by Progress
Thanks for the reply.
I tried an example also with database but when i click save state it doesn't save the sate in the db.
Here is my code based on an example:
DBStorageProvider.vb
Imports Microsoft.VisualBasic
Imports System.Runtime.Serialization
Imports Telerik.Web.UI.PivotGrid.Core
Imports Telerik.Web.UI.PivotGrid.Xmla
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports Telerik.Web.UI.PersistenceFramework
Public Class DBStorageProvider
Implements IStateStorageProvider
'Declare a global SqlConnection SqlConnection
Private SqlConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("ProfilerConnectionString").ConnectionString)
'Declare a global SqlDataAdapter SqlDataAdapter
Public SqlDataAdapter As New SqlDataAdapter()
'Declare a global SqlCommand SqlCommand
Public SqlCommand As New SqlCommand()
Public Sub SaveStateToStorage(ByVal key As String, ByVal serializedState As String) Implements Telerik.Web.UI.PersistenceFramework.IStateStorageProvider.SaveStateToStorage
Dim userID As Integer = Integer.Parse(key)
Dim userSettings As String = serializedState
'Open the SqlConnection
SqlConnection.Open()
'Update Query to update the Datatable
Dim updateQuery As String = (Convert.ToString("UPDATE testTelerik set UserID='" + userID + "',UserSaveSettings='") & userSettings) + "'"
SqlCommand.CommandText = updateQuery
SqlCommand.Connection = SqlConnection
SqlCommand.ExecuteNonQuery()
'Close the SqlConnectio
SqlConnection.Close()
End Sub
Public Function LoadStateFromStorage(ByVal key As String) As String Implements Telerik.Web.UI.PersistenceFramework.IStateStorageProvider.LoadStateFromStorage
Dim selectQuery As String = (Convert.ToString("SELECT UserID, UserSaveSettings FROM testTelerik WHERE UserID = '") & key) + "'"
Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = New SqlCommand(selectQuery, SqlConnection)
Dim myDataTable As New DataTable()
SqlConnection.Open()
Try
adapter.Fill(myDataTable)
Finally
SqlConnection.Close()
End Try
Return myDataTable.Rows(0)("UserSaveSettings").ToString()
End Function
End Class
default.aspx
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
<telerik:RadPersistenceManager runat="server" ID="RadPersistenceManager1">
<PersistenceSettings>
<telerik:PersistenceSetting ControlID="RadPivotGrid1" />
</PersistenceSettings>
</telerik:RadPersistenceManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
<div >
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
<telerik:RadPivotGrid runat="server" PageSize="10" ID="RadPivotGrid1" TableLayout="Fixed" ShowColumnHeaderZone="false"
ShowRowHeaderZone="false" ColumnHeaderZoneText="ColumnHeaderZone"
height="600px" AutoGenerateColumns="False" AllowSorting="True" EnableZoneContextMenu="True" AllowPaging="True" Culture="he" EnableConfigurationPanel="true">
<ClientSettings EnableFieldsDragDrop="True" >
</ClientSettings>
<Fields>
<telerik:PivotGridRowField DataField="CompanyName" ></telerik:PivotGridRowField>
</Fields>
<ConfigurationPanelSettings DefaultDeferedLayoutUpdate="true" Position="Left" />
</telerik:RadPivotGrid>
</telerik:RadAjaxPanel>
</div>
<div> <asp:Button Text="Save state" ID="SaveState" OnClick="SaveState_Click" runat="server" />
<asp:Button Text="Load state" ID="LoadState" OnClick="LoadState_Click" runat="server" /></div>
default.aspx.vb
Imports System.Data
Imports Telerik.Web.UI
Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
RadPersistenceManager1.StorageProvider = New DBStorageProvider()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub SaveState_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim user As String = 3
RadPersistenceManager1.StorageProviderKey = user
RadPersistenceManager1.SaveState()
End Sub
Protected Sub LoadState_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim user As String = 1
RadPersistenceManager1.StorageProviderKey = user
RadPersistenceManager1.LoadState()
RadPivotGrid1.Rebind()
End Sub
Private Sub RadPivotGrid1_NeedDataSource(ByVal sender As Object, ByVal e As PivotGridNeedDataSourceEventArgs) Handles RadPivotGrid1.NeedDataSource
RadPivotGrid1.DataSource = Employers.DataAccess.EmployerDAL.GetEmployersByOrganization(1)
End Sub
End Class
Could you please elaborate more on the exact behavior? Are you receiving an error and if so can you please share it with us? Finally please ensure that the database setup reflects the used in the code(by that I mean the table names and fields).
Regards,
Angel Petrov
Telerik by Progress
Hi
The problem was that I was missing Handles Me.Init on the Page_Init event. Fixed that and it is working now.
Thanks for the response :)