开发者

Use an extension method in a DynamicLinq-query

开发者 https://www.devze.com 2023-03-19 15:58 出处:网络
I want to extend the filter behavior of a Telerik RadGrid. If the user for instance filters the grid with the following word \"michele\" it should also return the rows which include \"michèle\". This

I want to extend the filter behavior of a Telerik RadGrid. If the user for instance filters the grid with the following word "michele" it should also return the rows which include "michèle". This isn't supported out-of-the-box in the Telerik RadGrid. Therefore I wrote a extension method for the type String: public static bool IsSqlLikeMatch( this string input, string pattern ) { [...] }

As a second step I replaced the FilterExpression of the RadGrid like this:

this.MasterTableView.FilterExpression.Replace( "Contains", "IsSqlLikeMatch" );

But unfortunately I get the following error message:

No applicable method 'IsSqlLikeMatch' exists in type 'String'

The Telerik RadGrid uses DynamicLinq. So therefore my question: "Can I use extension methods in DynamicLinq"? And how do I accomplish this?

Edit 09/09/2011: I've contacted the Telerik support and this was their answer:

Unfortunately you could not extend the dynamic linq functions included into Telerik.Web.UI.dll. So your changes to the DynamicLinq class will not effected the ExpressionParser used internally into the RadControls. However you could try changing the Dynamic Linq library and perform custom filtering by getting the filter expression from the RadGrid parse and pass them to the changed Dynamic Linq class' method and bind the RadGrid to the return开发者_如何学Goed data. I have attached a small sample which demonstrates how to use RadGrid's filter/sort expressions to filter, sort and page through ObjectDataSource.


In order to use an extension method, you must have a using directive for the namespace of the class in which you defined the extension method.

So try putting your class in a namespace, and add using for it.

Also, be sure that this class is defined as public static.

0

精彩评论

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