hey.. I am attempting to get my grid to save their custom grouped setting for each of my users via the asp.net profile objects. this works for me when i am not using the ajax manager. (I am using the grid settings persistor sample for the guidelines. )
My question is this.. how to save the grid settings when the ajax call avoids the Render Sub.. I hae tried the goups changing but found that really ugly as you would have to apply it on each grid in the page. ( it also blew up each time saying the object no longer existed if you moved an item out)
If you have any ideas I would appreciate hearing them
.class file
.ascx file
source
My question is this.. how to save the grid settings when the ajax call avoids the Render Sub.. I hae tried the goups changing but found that really ugly as you would have to apply it on each grid in the page. ( it also blew up each time saying the object no longer existed if you moved an item out)
If you have any ideas I would appreciate hearing them
.class file
| Imports Microsoft.VisualBasic |
| 'Namespace WebApplication1 |
| Imports System |
| Imports System.Collections |
| Imports System.IO |
| Imports System.Web.UI |
| Imports System.Web.UI.WebControls |
| Imports Telerik.Web.UI |
| Public Class GridSettingsPersister |
| Private gridInstance As RadGrid |
| Public Sub New(ByVal gridInstance As RadGrid) |
| MyBase.New() |
| Me.gridInstance = gridInstance |
| End Sub |
| 'this method should be called on Render |
| Public Function SaveSettings() As String |
| Dim gridSettings() As Object = New Object((4) - 1) {} |
| 'Save groupBy |
| Dim groupByExpressions As GridGroupByExpressionCollection = gridInstance.MasterTableView.GroupByExpressions |
| Dim groupExpressions() As Object = New Object((groupByExpressions.Count) - 1) {} |
| Dim count As Integer = 0 |
| For Each expression As GridGroupByExpression In groupByExpressions |
| groupExpressions(count) = CType(expression, IStateManager).SaveViewState |
| count = (count + 1) |
| Next |
| gridSettings(0) = groupExpressions |
| 'Save sort expressions |
| gridSettings(1) = CType(gridInstance.MasterTableView.SortExpressions, IStateManager).SaveViewState |
| 'Save columns order |
| Dim columnsLength As Integer = (gridInstance.MasterTableView.Columns.Count + gridInstance.MasterTableView.AutoGeneratedColumns.Length) |
| Dim columnOrder() As Pair = New Pair(columnsLength - 1) {} |
| Dim allColumns As ArrayList = New ArrayList(columnsLength) |
| allColumns.AddRange(gridInstance.MasterTableView.Columns) |
| allColumns.AddRange(gridInstance.MasterTableView.AutoGeneratedColumns) |
| Dim i As Integer = 0 |
| For Each column As GridColumn In allColumns |
| Dim p As Pair = New Pair |
| p.First = column.OrderIndex |
| p.Second = column.HeaderStyle.Width |
| columnOrder(i) = p |
| i = (i + 1) |
| Next |
| gridSettings(2) = columnOrder |
| 'Save filter expression |
| gridSettings(3) = CType(gridInstance.MasterTableView.FilterExpression, Object) |
| Dim formatter As LosFormatter = New LosFormatter |
| Dim writer As StringWriter = New StringWriter |
| formatter.Serialize(writer, gridSettings) |
| Return writer.ToString |
| End Function |
| 'this method should be called on PageInit |
| Public Sub LoadSettings(ByVal settings As String) |
| Dim formatter As LosFormatter = New LosFormatter |
| Dim reader As StringReader = New StringReader(settings) |
| Dim gridSettings() As Object = CType(formatter.Deserialize(reader), Object()) |
| 'Load groupBy |
| Dim groupByExpressions As GridGroupByExpressionCollection = Me.gridInstance.MasterTableView.GroupByExpressions |
| groupByExpressions.Clear() |
| Dim groupExpressionsState() As Object = CType(gridSettings(0), Object()) |
| Dim count As Integer = 0 |
| For Each obj As Object In groupExpressionsState |
| Dim expression As GridGroupByExpression = New GridGroupByExpression |
| CType(expression, IStateManager).LoadViewState(obj) |
| groupByExpressions.Add(expression) |
| count = (count + 1) |
| Next |
| 'Load sort expressions |
| Me.gridInstance.MasterTableView.SortExpressions.Clear() |
| CType(Me.gridInstance.MasterTableView.SortExpressions, IStateManager).LoadViewState(gridSettings(1)) |
| 'Load columns order |
| Dim columnsLength As Integer = (Me.gridInstance.MasterTableView.Columns.Count + Me.gridInstance.MasterTableView.AutoGeneratedColumns.Length) |
| Dim columnOrder() As Pair = CType(gridSettings(2), Pair()) |
| If (columnsLength = columnOrder.Length) Then |
| Dim allColumns As ArrayList = New ArrayList(columnsLength) |
| allColumns.AddRange(Me.gridInstance.MasterTableView.Columns) |
| allColumns.AddRange(Me.gridInstance.MasterTableView.AutoGeneratedColumns) |
| Dim i As Integer = 0 |
| For Each column As GridColumn In allColumns |
| column.OrderIndex = CType(columnOrder(i).First, Integer) |
| column.HeaderStyle.Width = CType(columnOrder(i).Second, Unit) |
| i = (i + 1) |
| Next |
| End If |
| 'Load filter expression |
| Me.gridInstance.MasterTableView.FilterExpression = CType(gridSettings(3), String) |
| End Sub |
| End Class |
| <Serializable()> Public Class Pet |
| Public Sub New() |
| ' default ctor required for serializer |
| End Sub |
| Private _names As New Hashtable() |
| Public Property Names() As Hashtable |
| Get |
| Return _names |
| End Get |
| Set(ByVal value As Hashtable) |
| _names = value |
| End Set |
| End Property |
| Public Sub SavePetNames(ByVal Grid As RadGrid, ByVal GridName As String) |
| Dim settings As New GridSettingsPersister(Grid) |
| Dim settingvalue As String = settings.SaveSettings() |
| _names(GridName) = settingvalue |
| ' _names.Add(GridName, settingvalue) |
| End Sub |
| End Class |
| 'End Namespace |
.ascx file
| Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init |
| ' export.Visible = True |
| For Each c As Control In Me.Controls |
| If TypeOf c Is RadGrid Then |
| Dim settings As New GridSettingsPersister(c) |
| If Profile.Pet.Names.ContainsKey(functions.getunique(c)) Then |
| settings.LoadSettings(Profile.Pet.Names(functions.getunique(c)).ToString()) |
| End If |
| End If |
| Next |
| End Sub |
| Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter) |
| MyBase.Render(writer) |
| For Each c As Control In Me.Controls |
| If TypeOf c Is RadGrid Then |
| Profile.Pet.SavePetNames(c, functions.getunique(c)) |
| End If |
| Next |
| End Sub |
| Protected Sub RadGrid1_GroupsChanging(ByVal source As Object, ByVal e As Telerik.Web.UI.GridGroupsChangingEventArgs) Handles RadGrid1.GroupsChanging |
| 'This doesn't work |
| ' Profile.Pet.SavePetNames(RadGrid1, functions.getunique(RadGrid1)) |
| End Sub |
source
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="RadGrid1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </telerik:RadAjaxManager> |