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

[Solved] Use dynamic LINQ for query generated by RadGrid

1 Answer 404 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leonid Raichman
Top achievements
Rank 1
Leonid Raichman asked on 08 Jan 2010, 06:01 PM
HI ,

I have a RadGrid with a column of type GridDateTimeColumn :

  <telerik:RadGrid ID="RadGrid1 > 
       <Columns> 
                  <telerik:GridDateTimeColumn DataField="CreationDate" DataType="System.DateTime " />  
       <Columns> 
  </telerik:RadGrid> 

On this column I have a DateTime picker which allows me to select some date and then I want to apply a filter , for example "GreaterThan" . I am expecting that the result will be all rows with a date CreationDate greater than selected.

In my code I am sending a filter expression generated by a grid to dynamic linq query like this : 
//data is IEnumerable collection of data objects 
// filter is a filter expression generated by grid , which is converted to string like this :  
//string filter  = string.format("{0}.{1}(\"{2}\")",item.FieldName, item.FilterFunction, item.FieldValue) 
  IQueryable query = data.AsQueryable(); 
  queryquery = query.Where(filter); 

At this point I am getting an exception : 
No applicable method 'GreaterThan' exists in dataObjectType 'DateTime'

Is there any way to make it work with dynamic linq ? it will be work with most cases when column type is string, but I need to make it work with INT and DateTime column types .

Any suggestion ? ? ?
Thanks  . 

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 11 Jan 2010, 08:48 AM
Hello Leonid,

Correct expression format in your case is: "it.{0} > DateTime.Parse(""{1}"")".
For your convenience I am attaching sample project demonstrating how this works.

Kind regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Leonid Raichman
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or