This is a migrated thread and some comments may be shown as answers.

RadGrid Default Filtering not working

5 Answers 1796 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 02 Dec 2013, 02:48 PM
Hello,

I'm trying to render a RadGrid with default filtering as explained here. I've managed to configure the grid so that filter controls are set when the page loads, but the data in the grid is not filtered. I suspect that I've missed something simple so here's my code for you to laugh at:
ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager id="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
        </Scripts>
    </telerik:RadScriptManager>
    <script type="text/javascript">
        //Put your JavaScript code here.
    </script>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    </telerik:RadAjaxManager>
    <div>
        <telerik:RadGrid ID="rgdUsers" runat="server"
            AutoGenerateColumns="false"
            AllowFilteringByColumn="true"
            OnNeedDataSource="rgdUsers_NeedDataSource"
            OnPreRender="rgdUsers_PreRender"  >
            <MasterTableView DataKeyNames="Id, Active, Name, Surname"  >
                <Columns>
                    <telerik:GridBoundColumn UniqueName="ActiveColumn" DataField="Active" HeaderText="Active"
                        AutoPostBackOnFilter="true"
                        CurrentFilterFunction="EqualTo"
                        CurrentFilterValue="True" />
                    <telerik:GridBoundColumn UniqueName="NameColumn" DataField="Name" HeaderText="Name" />
                    <telerik:GridBoundColumn UniqueName="SurnameColumn" DataField="Surname" HeaderText="Surname" />
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
    </div>
    </form>
</body>
</html>

C#
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Linq;
 
using Telerik.Web.UI;
 
public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
 
    protected void rgdUsers_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        using (SwmpHermesEntities ent = new SwmpHermesEntities())
        {
            var Users = ent.Users.ToList();
            rgdUsers.DataSource = Users;
        }
    }
 
    protected void rgdUsers_PreRender(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            rgdUsers.MasterTableView.FilterExpression = "([Active] = True)";
 
            GridColumn activeColumn = rgdUsers.MasterTableView.GetColumnSafe("ActiveColumn");
            activeColumn.CurrentFilterFunction = GridKnownFunction.EqualTo;
            activeColumn.CurrentFilterValue = "True";
        }
    }
}

If I toggle the Active column checkbox, the grid behaves as expected. I'm using RadControls for ASP.NET AJAX Q2 2013.

Thanks in advance,
Matt

5 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 03 Dec 2013, 03:33 AM
Hi Matt,

Please note that after setting the filter, you must rebind the grid:

C#:
protected void rgdUsers_PreRender(object sender, EventArgs e)
{
  if (!this.IsPostBack)
   {
     rgdUsers.MasterTableView.FilterExpression = "([Active] = True)";
     GridColumn activeColumn = rgdUsers.MasterTableView.GetColumnSafe("ActiveColumn");
     activeColumn.CurrentFilterFunction = GridKnownFunction.EqualTo;
     activeColumn.CurrentFilterValue = "True";
     rgdUsers.Rebind();
   }
}

Thanks,
Princy
0
Matt
Top achievements
Rank 1
answered on 03 Dec 2013, 08:46 AM
Hi Princy, thanks for the reply.

When I call the Rebind() I get an exception :(

Telerik.Web.UI.ParseException was unhandled by user code
  HResult=-2146233088
  Message=Expression expected
  Source=Telerik.Web.UI
  Position=1
  StackTrace:
       at Telerik.Web.UI.ExpressionParser.ParsePrimaryStart()
       at Telerik.Web.UI.ExpressionParser.ParsePrimary()
       at Telerik.Web.UI.ExpressionParser.ParseUnary()
       at Telerik.Web.UI.ExpressionParser.ParseMultiplicative()
       at Telerik.Web.UI.ExpressionParser.ParseAdditive()
       at Telerik.Web.UI.ExpressionParser.ParseComparison()
       at Telerik.Web.UI.ExpressionParser.ParseLogicalAnd()
       at Telerik.Web.UI.ExpressionParser.ParseLogicalOr()
       at Telerik.Web.UI.ExpressionParser.ParseExpression()
       at Telerik.Web.UI.ExpressionParser.ParseParenExpression()
       at Telerik.Web.UI.ExpressionParser.ParsePrimaryStart()
       at Telerik.Web.UI.ExpressionParser.ParsePrimary()
       at Telerik.Web.UI.ExpressionParser.ParseUnary()
       at Telerik.Web.UI.ExpressionParser.ParseMultiplicative()
       at Telerik.Web.UI.ExpressionParser.ParseAdditive()
       at Telerik.Web.UI.ExpressionParser.ParseComparison()
       at Telerik.Web.UI.ExpressionParser.ParseLogicalAnd()
       at Telerik.Web.UI.ExpressionParser.ParseLogicalOr()
       at Telerik.Web.UI.ExpressionParser.ParseExpression()
       at Telerik.Web.UI.ExpressionParser.Parse(Type resultType)
       at Telerik.Web.UI.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
       at Telerik.Web.UI.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values)
       at Telerik.Web.UI.GridDynamicQueryable.Where(IQueryable source, String predicate, Object[] values)
       at Telerik.Web.UI.GridDataTableFromEnumerable.FillData35()
       at Telerik.Web.UI.GridDataTableFromEnumerable.FillData()
       at Telerik.Web.UI.GridResolveEnumerable.Initialize()
       at Telerik.Web.UI.GridResolveEnumerable.EnsureInitialized()
       at Telerik.Web.UI.GridResolveEnumerable.get_DataTable()
       at Telerik.Web.UI.GridEnumerableFromDataView..ctor(GridTableView owner, IEnumerable enumerable, Boolean CaseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText)
       at Telerik.Web.UI.GridDataSourceHelper.CreateGridEnumerable(GridTableView owner, IEnumerable enumerable, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText)
       at Telerik.Web.UI.GridDataSourceHelper.GetResolvedDataSource(GridTableView owner, Object dataSource, String dataMember, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText)
       at Telerik.Web.UI.GridTableView.get_ResolvedDataSource()
       at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource)
       at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
       at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
       at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
       at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
       at Telerik.Web.UI.GridTableView.PerformSelect()
       at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
       at Telerik.Web.UI.GridTableView.DataBind()
       at Telerik.Web.UI.RadGrid.DataBind()
       at Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason)
       at Telerik.Web.UI.RadGrid.Rebind()
       at Default.rgdUsers_PreRender(Object sender, EventArgs e) in c:\Projects\Personal\RadControlsWebSite2\RadControlsWebSite2\Default.aspx.cs:line 43
       at System.Web.UI.Control.OnPreRender(EventArgs e)
       at System.Web.UI.WebControls.BaseDataBoundControl.OnPreRender(EventArgs e)
       at Telerik.Web.UI.RadCompositeDataBoundControl.OnPreRender(EventArgs e)
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Control.PreRenderRecursiveInternal()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 


0
Accepted
Princy
Top achievements
Rank 2
answered on 03 Dec 2013, 08:53 AM
Hi Matt,

Please try setting EnableLinqExpressions="false" in your code.

ASPX:
<telerik:RadGrid ID="rgdUsers" runat="server" EnableLinqExpressions="false". . .>

Thanks,
Princy
0
Matt
Top achievements
Rank 1
answered on 03 Dec 2013, 08:56 AM
Bingo! Thanks Princy, thats fixed it!
0
Santhosh
Top achievements
Rank 1
answered on 26 Nov 2015, 11:01 AM

Hi Princy,

 

Can you please help me with my issue here.

Inner Exception Type: Telerik.Web.UI.ParseException
Inner Exception: Expression expected
Inner Source: Telerik.Web.UI
Inner Stack Trace: 
   at Telerik.Web.UI.ExpressionParser.ParsePrimaryStart()
   at Telerik.Web.UI.ExpressionParser.ParsePrimary()
   at Telerik.Web.UI.ExpressionParser.ParseUnary()
   at Telerik.Web.UI.ExpressionParser.ParseMultiplicative()
   at Telerik.Web.UI.ExpressionParser.ParseAdditive()
   at Telerik.Web.UI.ExpressionParser.ParseComparison()
   at Telerik.Web.UI.ExpressionParser.ParseLogicalAnd()
   at Telerik.Web.UI.ExpressionParser.ParseLogicalOr()
   at Telerik.Web.UI.ExpressionParser.ParseExpression()
   at Telerik.Web.UI.ExpressionParser.ParseParenExpression()
   at Telerik.Web.UI.ExpressionParser.ParsePrimaryStart()
   at Telerik.Web.UI.ExpressionParser.ParsePrimary()
   at Telerik.Web.UI.ExpressionParser.ParseUnary()
   at Telerik.Web.UI.ExpressionParser.ParseMultiplicative()
   at Telerik.Web.UI.ExpressionParser.ParseAdditive()
   at Telerik.Web.UI.ExpressionParser.ParseComparison()
   at Telerik.Web.UI.ExpressionParser.ParseLogicalAnd()
   at Telerik.Web.UI.ExpressionParser.ParseLogicalOr()
   at Telerik.Web.UI.ExpressionParser.ParseExpression()
   at Telerik.Web.UI.ExpressionParser.Parse(Type resultType)
   at Telerik.Web.UI.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
   at Telerik.Web.UI.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values)
   at Telerik.Web.UI.GridDynamicQueryable.Where(IQueryable source, String predicate, Object[] values)
   at Telerik.Web.UI.GridDataTableFromEnumerable.FillData35()
   at Telerik.Web.UI.GridDataTableFromEnumerable.FillData()
   at Telerik.Web.UI.GridResolveEnumerable.Initialize()
   at Telerik.Web.UI.GridResolveEnumerable.EnsureInitialized()
   at Telerik.Web.UI.GridEnumerableFromDataView..ctor(GridTableView owner, DataView dataView, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText)
   at Telerik.Web.UI.GridDataSourceHelper.CreateGridEnumerable(GridTableView owner, IEnumerable enumerable, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText)
   at Telerik.Web.UI.GridDataSourceHelper.GetResolvedDataSource(GridTableView owner, Object dataSource, String dataMember, Boolean caseSensitive, Boolean autoGenerateColumns, GridColumnCollection presentColumns, String[] additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText)
   at Telerik.Web.UI.GridTableView.get_ResolvedDataSource()
   at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource)
   at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
   at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
   at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
   at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
   at Telerik.Web.UI.GridTableView.PerformSelect()
   at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
   at Telerik.Web.UI.GridTableView.DataBind()
   at Telerik.Web.UI.GridTableView.Rebind()
   at suntech.OrderList.CustomerCombo_SelectedIndexChanged(Object sender, RadComboBoxSelectedIndexChangedEventArgs e) in c:\santhosh\SuntechERP\suntech\suntech\suntech\OrderList.aspx.cs:line 643
   at Telerik.Web.UI.RadComboBox.OnSelectedIndexChanged()
   at Telerik.Web.UI.RadComboBox.RaisePostDataChangedEvent()
   at Telerik.Web.UI.RadDataBoundControl.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
   at System.Web.UI.Page.RaiseChangedEvents()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Exception Type: System.Web.HttpUnhandledException
Exception: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Source: DefaultPage
Stack Trace: 
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.orderlist_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\suntech\5ec9e0ec\2bfbf1d9\App_Web_m4jwchmn.0.cs:line 0
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Matt
Top achievements
Rank 1
Santhosh
Top achievements
Rank 1
Share this question
or