开发者

How to use radgrid's FilterExpression with Linq

开发者 https://www.devze.com 2023-02-07 22:23 出处:网络
I have a radgrid and when I filter, I get something like: \"(iif(Name== null, \\\"\\\",Name).ToString().ToUpper().Contains(\\\"ap\\\".ToUpper()))\"

I have a radgrid and when I filter, I get something like:

"(iif(Name== null, \"\",  Name).ToString().ToUpper().Contains(\"ap\".ToUpper()))"

In my Linq Data Source Selecting event, I would like to use this filter in my results by doing something like results = results.Where(FilterExre开发者_StackOverflow社区ssion), but this is not working.


Here is what I've used:

var filterExpression = gridOrderLineItems.MasterTableView.FilterExpression;
if (!string.IsNullOrEmpty(filterExpression))
   allItems = allItems.AsQueryable()
              .Where(filterExpression)
              .ToList();

As you can see from Telerik documentation, there are two filter modes in RadGrid. One is Lynq Dynamic and another one is SQL-like. I think the default is dynamic, provided that your datasource supports it. I had one case where the grid was using SQL syntax because the datasource was IEnumerable and I had to changed it to List in order to enable dynamic expression. You can see what mode the grid is in by simply checking FilterExpression property. There is EnableLinqExpressions property you can play with as well.


I think you want something like results.Where(i=>(i.Name+"").ToString().ToUpper().Contains("ap".ToUpper())))


My Solution

var z = RadGrid2.MasterTableView.FilterExpression;
            string filter = "";
            if (z.Split('\"').Length > 3)
            {
                string v = "'" + z.Split('\"')[3] + "'";
                string c = z.Split('\"')[0];
                string opr = " like ";
                c = c.Replace("(iif(", "").Replace(" ", "").Replace("==", "").Replace("null", "").Replace(",", "");

                filter = c + opr + v ;
            }
            else
                filter = z;


            e.InputParameters["filterExpression"] = filter;
0

精彩评论

暂无评论...
验证码 换一张
取 消