Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Applying default filter on initial load - cannot be applied

Answered Applying default filter on initial load - cannot be applied

Feed from this thread
  • tomas Intermediate avatar

    Posted on Feb 25, 2009 (permalink)

    Hello.

    I am trying to set up the grid default filter, but i cannot. Your example is wrong.

    Why?

    I am binding the grid using the NeedDataSource in the same way as you are writing in Advanced Data-binding (using NeedDataSourceEvent).

    I can read:

    If you are binding the grid using the NeedDataSource event, you can set the initial filter in the NeedDataSource event handler and omit the call to the Rebind method. The code for setting the filter must still be placed inside an if statement that checks that Page.IsPostBack is False.

    No, It cannot be done.

    Reason?

    Grid has no columns at this time. RadGrid1.MasterTableView.GetColumnSafe("") always returns null. (although datasource has already be assigned).

    I also don't need to call  RadGrid1.MasterTableView.FilterExpression = "SQL expression" because my data has been already filtered. I am using SQL SERVER power to do that and I think that everybody must prefer server technology for this type of task.

    So I must use PreRender event, but:

    (!)

    I must call this.RadGrid1.Rebind(); If I don't, the filter function is preselected, but filter value TextBox is empty !!!!

    What does Rebind do really? MY grid has thousands of rows. Is it really needed to call rebind because of one value needs to be inserted in a TextBox? The filter function is preselected, so why TextBox is empty?

    Thank you very much.

    Tom


    Reply

  • Iana Tsolova Iana Tsolova admin's avatar

    Posted on Feb 27, 2009 (permalink)

    Hi tomas,

    Straight to your questions:
    Calling the Rebind() method of RadGrid would explicitly fire the NeedDataSource event. And further information on the grid lifecycle is available in the below articles:

    http://www.telerik.com/help/aspnet-ajax/grdeventsequence.html
    http://www.telerik.com/help/aspnet-ajax/grdcommandsthatinvokerebindimplicitly.html

    In order appropriate text to be set in the filter textBox and the corresponding filter function to be selected, as it is done in this help topic:
     
    protected void RadGrid1_PreRender(object sender, System.EventArgs e)  
    {  
     if (!Page.IsPostBack)  
     {  
       RadGrid1.MasterTableView.FilterExpression = "([Country] LIKE \'%Germany%\') ";  
       GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("Country");  
       column.CurrentFilterFunction = GridKnownFunction.Contains;  
       column.CurrentFilterValue = "Germany";  
       RadGrid1.MasterTableView.Rebind();  
     }  
    }  

    Give it a try and let me know how it goes.

    All the best,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.
  • tomas Intermediate avatar

    Posted on Mar 3, 2009 (permalink)

    Hello Lana and all Telerik team.

    I know your sample. 

    Please, answer me, why my grid does not work, as you are writing.

    ---
    If you are binding the grid using the NeedDataSource event, you can set the initial filter in the NeedDataSource event handler and omit the call to the Rebind method. The code for setting the filter must still be placed inside an if statement that checks that Page.IsPostBack is False.

    I want to omit the call to the Rebind method. But It cannot be done.

    Reason?

    Grid has no columns at this time. RadGrid1.MasterTableView.GetColumnSafe("") always returns null. (although datasource has already be assigned).
    ---

    Also you are writing:

    Calling the Rebind() method of RadGrid would explicitly fire the NeedDataSource event.

    It seems to me, that this is not correct.

    I am calling rebind in the PreRender method. NeedDataSource method is not called again.

    Thank you Tom

    Reply

  • Answer Iana Tsolova Iana Tsolova admin's avatar

    Posted on Mar 6, 2009 (permalink)

    Hello tomas,

    The GetColumnSafe method could return null in case you are using auto generated column. This is because the auto generated column are created on later stage, after the NeedDataSource event is executed. Therefore you need to rebind the grid on grid PreRender event to apply the initial filer expression when AutoGenerateColumns property is set to true.

    I will updated the help topic in question according to the upper information.

    Please excuse us for the inconvenience.


    Best wishes,
    Iana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

    Reply

  • sameer avatar

    Posted on Jul 24, 2011 (permalink)

    Secenario:
        EntityDataSource
        RadGrid
        

    <

    telerik:RadGrid ID="rgView" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" CellSpacing="0" GridLines="None" ShowGroupPanel="True" AutoGenerateColumns="False"  DataSourceID="edsEst" onprerender="rgView_PreRender"

    Returns the following error while trying to set the initial filter for Grid in the Grid_PreRender event (Version Q2 2011):

    could not be resolved in the current scope or context. Make sure that all referenced variables are in scope, that required schemas are loaded, and that namespaces are referenced correctly

    Reply

  • OfficeBooks Team avatar

    Posted on Feb 23, 2012 (permalink)

    Hi, after some time I found a solution for this problem

    Disable the radgrid property EnableLinqExpressions

    This will allow to find the missing fields on filter

    Reply

  • Say Hello to Telerik's PivotGrid for ASP.NET AJAX, Silverlight, WPF and WinForms. Now packed with OLAP support.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Applying default filter on initial load - cannot be applied
Related resources for "Applying default filter on initial load - cannot be applied"

ASP.NET Grid Features  |  Documentation  |  Demos  |  Step-by-step Tutorial  ]