I build my (ajaxified) grid up dynamically in code. I do that in the Page_Init event so virtual paging is correctly implemented. On every column I have added the AutoPostBackOnFilter = True. When you do this and the user types in the filter in a second column, the filter that was set in the first column is lost.
I guess this is because the grid is recreated and the CurrentFilterFunction and CurrentFilterValue are not persisted because I create the columns dynamically. What is the best solution to solve this?
                                I guess this is because the grid is recreated and the CurrentFilterFunction and CurrentFilterValue are not persisted because I create the columns dynamically. What is the best solution to solve this?
6 Answers, 1 is accepted
0
                                Hello Ewald,
I have tried to reproduce the issue locally, but without success. Attached is a small sample that works as expected. Please review it and let me know whether I miss something.
In addition I would suggest that you check this online example that demonstrates RadGrid programmatic creation on Page_Init event.
I hope this helps.
All the best,
Martin
the Telerik team
                                        I have tried to reproduce the issue locally, but without success. Attached is a small sample that works as expected. Please review it and let me know whether I miss something.
In addition I would suggest that you check this online example that demonstrates RadGrid programmatic creation on Page_Init event.
I hope this helps.
All the best,
Martin
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
0
                                
                                                    Ewald
                                                    
                                            
    Top achievements
    
            
                
                Rank 1
            
    
                                                
                                                answered on 17 Oct 2011, 09:24 PM
                                            
                                        I have created a simple repro. 
Steps
1. Enter a filter value in the first column
2. Enter a filter value in the second column
Actual result
The first filter value is removed, there is only a filter on the second column
Expected result
Both filter values are applied
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
                                        Steps
1. Enter a filter value in the first column
2. Enter a filter value in the second column
Actual result
The first filter value is removed, there is only a filter on the second column
Expected result
Both filter values are applied
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"    CodeBehind="Default.aspx.vb" Inherits="TweedeFilter._Default" %><asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content><asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">   <telerik:RadScriptManager ID="RadScriptManager" runat="server" AsyncPostBackTimeout="0" />   <asp:PlaceHolder ID="ph" runat="server" /></asp:Content>Imports Telerik.Web.UIPublic Class _Default    Inherits System.Web.UI.Page    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init        ph.Controls.Add(BuildGrid())    End Sub    Private Function BuildGrid() As RadGrid        Dim col1 = "col1"        Dim col2 = "col2"        Dim ret = New RadGrid() With {                .EnableViewState = True,                .ID = "myId",                .AutoGenerateColumns = False                }        ret.MasterTableView.EnableColumnsViewState = False        ret.AllowFilteringByColumn = True        ret.EnableLinqExpressions = False        AddHandler ret.NeedDataSource, Sub(sender As Object, e As GridNeedDataSourceEventArgs)                                           Loaddata(ret)                                       End Sub        ret.Columns.Add(New GridBoundColumn() With {.DataField = col1, .AutoPostBackOnFilter = True})        ret.Columns.Add(New GridBoundColumn() With {.DataField = col2, .AutoPostBackOnFilter = True})        Return ret    End Function    Private Sub Loaddata(ret As RadGrid)        Dim col1 = "col1"        Dim col2 = "col2"        Dim dt As New DataTable        dt.Columns.Add(col1, GetType(String))        dt.Columns.Add(col2, GetType(String))        dt.LoadDataRow(New Object() {"bb", "cc"}, True)        dt.LoadDataRow(New Object() {"bb", "ff"}, True)        dt.LoadDataRow(New Object() {"cc", "ff"}, True)        dt.LoadDataRow(New Object() {"cc", "cc"}, True)        dt.LoadDataRow(New Object() {"dd", "cc"}, True)        dt.LoadDataRow(New Object() {"dd", "ff"}, True)        dt.LoadDataRow(New Object() {"ee", "ff"}, True)        dt.LoadDataRow(New Object() {"ee", "cc"}, True)        ret.DataSource = dt    End SubEnd Class0
                                Accepted
Hello Ewald,
Reviewing your code I noticed that you have disabled the viewstate of the columns in your grid:
Please turn the columns viewstate on and let me know whether the problem persists.
Kind regards,
Martin
the Telerik team
                                        Reviewing your code I noticed that you have disabled the viewstate of the columns in your grid:
Private Function BuildGrid() As RadGrid    ...    ret.MasterTableView.EnableColumnsViewState = False    ...End FunctionPlease turn the columns viewstate on and let me know whether the problem persists.
Kind regards,
Martin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
                                
                                                    Ewald
                                                    
                                            
    Top achievements
    
            
                
                Rank 1
            
    
                                                
                                                answered on 18 Oct 2011, 12:36 PM
                                            
                                        Thanks. That did the trick. 
I needed it at one point due to http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html. But it seems that I don't need it anymore.
                                        I needed it at one point due to http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html. But it seems that I don't need it anymore.
0
                                
                                                    Rohan
                                                    
                                            
    Top achievements
    
            
                
                Rank 1
            
    
                                                
                                                answered on 14 Feb 2012, 03:11 PM
                                            
                                        i am new in TELERIK Control , How to add filter to dynamically created RADGRID 's Template field .
                                        0
                                
                                                    Princy
                                                    
                                            
    Top achievements
    
            
                
                Rank 2
            
    
                                                
                                                answered on 15 Feb 2012, 06:23 AM
                                            
                                        Hello,
The FilterTemplates for the TemplateColumns can be created and assigned dynamically, in the same way as the ItemTemplates and EditTemplates as explained in the following help documentation.
Programmatic Creation.
Thanks,
Princy.
                                        The FilterTemplates for the TemplateColumns can be created and assigned dynamically, in the same way as the ItemTemplates and EditTemplates as explained in the following help documentation.
Programmatic Creation.
Thanks,
Princy.