Using Radgrid filter expression to query collection gives exception 'Expression Expected' c# dynamic-linq telerik telerik-grid


I am trying to query a collection using the filter expression from my radgrid. On the RadGrid I have the property of EnableLinqExpressions = "false"

However I get the exception Expression Expected when using the code:

results = results.Where(filterExpression);

At the moment the filter expression is in the format "(([SCRIPT_AGENT] = 'Jack Davies'))"

How can I solve this issue?

When I enter the following it works:

results = results.Where("SCRIPT_AGENT == @0", "Jack Davies")

Is there anyway to use my current filter expression or is there someway to convert it into a usable format?

2/18/2016 12:23:17 PM

Accepted Answer

Instead of using the filter expression of the rad grid I decided to use a different approach and use the current data in the rad grid itself when a filter is applied:

        // If there is a filter applied then enter the loop if there isn't then the filter expression will be empty 
        if (!String.IsNullOrEmpty(filterExpression))
            // Create a new list of strings to hold the sequence ids
            List<string> sequenceIds = new List<string>();

            // For each row in the radgrid...
            foreach (GridDataItem row in rgCallRecordings.Items) // loops through each rows in RadGrid
                // ...Add the sequence id to the list
            // Only return results whose sequence ids are in the list
            results = results.Where(a => sequenceIds.Contains(a.SEQUENCE_ID));                

This eliminated the error and produced the same results as using the filter expressions.

2/18/2016 4:23:16 PM

Related Questions

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow