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

"Expression Expected" on initial filter

8 Answers 298 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Toxic
Top achievements
Rank 1
Toxic asked on 18 Jun 2013, 11:51 AM

I am trying to set an initial filter on a radgrid.

I have used the code in the prerender      

receiptlist.MasterTableView.FilterExpression = "([receiptlist] LIKE '%148047%')" 
        Dim column As GridColumn = receiptlist.MasterTableView.GetColumnSafe("receiptlist")
        column.CurrentFilterFunction = GridKnownFunction.Contains
        column.CurrentFilterValue = "148047"
        receiptlist.Rebind()

And have set the uniquename of the column to "receiptlist" and also made the columns filterable.

Unfortunately I get the "expression expected" error on the rebind.

Any ideas?

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 18 Jun 2013, 12:15 PM
Hi,

Please set EnableLinqExpression=false in the radgrid.

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

Thanks,
Princy
0
Toxic
Top achievements
Rank 1
answered on 18 Jun 2013, 12:38 PM
Thanks princy, that fixes the error. Would be good if they perhaps included this in the example.........

Unfortunately even though the filter appears in the box at the top the list isn't filtered......

Am I missing something?
0
Toxic
Top achievements
Rank 1
answered on 18 Jun 2013, 12:40 PM
That works thanks princy, or at least stops the error. 

But it still isn't filtering the data???!

Any ideas?
0
Princy
Top achievements
Rank 1
answered on 19 Jun 2013, 03:51 AM
Hi Toxic,

The Contains is a filter function which is not for the int data type,so you can't set it like this "([receiptlist] LIKE '%148047%')" ,
this is only for string values.
Please have a look in this documentation,it describes about the filter function for String and Int data types.
Operating with the FilterExpression

Thanks,
Princy
0
JD
Top achievements
Rank 1
answered on 18 Sep 2013, 09:17 PM
This answer, in particular "EnableLinqExpressions=false", needs to be associated with every thread containing keywords Initial, Filter and RadGrid.  Would have saved me a few hours.  :)

0
Andry
Top achievements
Rank 1
answered on 05 Oct 2013, 02:08 PM
My EnableLinqExpressions is set false, but the "Expression expected" error is still there.

    protected void RGSalesPreRender(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                rgSales.MasterTableView.FilterExpression = "([SalesID] = " + Request.QueryString["ID"] + ")";

                GridColumn column = rgSales.MasterTableView.GetColumnSafe("SalesID");

                column.CurrentFilterFunction = GridKnownFunction.EqualTo;
                column.CurrentFilterValue = Request.QueryString["ID"];

                rgSales.MasterTableView.Rebind();
            }
        }
    }

 

Does anyone have any idea?
0
Princy
Top achievements
Rank 1
answered on 07 Oct 2013, 12:10 PM
Hi Andry,

I'm not sure what is causing the issue,the code works fine at my end.Please try the sample code snippet,if this doesn't help,please provide your full code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false"  AllowFilteringByColumn="true" EnableLinqExpressions="false" OnPreRender="RadGrid1_PreRender">
            <MasterTableView>
                <Columns>
                    <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />
                    <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
              </Columns>
            </MasterTableView>
    </telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
   {
       if (!Page.IsPostBack)
       {
           if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
           {
               RadGrid1.MasterTableView.FilterExpression = "([OrderID] = " + Request.QueryString["ID"] + ")";
 
               GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("OrderID");
 
               column.CurrentFilterFunction = GridKnownFunction.EqualTo;
               column.CurrentFilterValue = Request.QueryString["ID"];
 
               RadGrid1.MasterTableView.Rebind();
           }
       }
   }
 
protected void Button1_Click(object sender, EventArgs e)
   {
       string v = "10289";
       Response.Redirect("Filter.aspx?ID=" +v);
   }

Thanks,
Princy
0
Andry
Top achievements
Rank 1
answered on 07 Oct 2013, 12:30 PM
Hi Princy,

I found what's wrong.

My code was:
rgSales.MasterTableView.FilterExpression = "([SalesID] = " + Request.QueryString["ID"] + ")";

And removing the square brackets make it work!!
rgSales.MasterTableView.FilterExpression = "(SalesID = " + Request.QueryString["ID"] + ")";

Thank you Princy!
Tags
Grid
Asked by
Toxic
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Toxic
Top achievements
Rank 1
JD
Top achievements
Rank 1
Andry
Top achievements
Rank 1
Share this question
or