I'm using an SPGridView that displays search results and it works perfectly. Sorting and filtering works fine as well unless for the DateTime Column. When I'm trying to filter by Date I have the following error:

Cannot perform Like Operation on System.DateTime and System.String

I do know the cause of this message is that 'like' operation should have two strings to compare. I would like to know how to use FilteredDataSourcePropertyFormat in order to be able to handle DateTime. You can read a relevent part of my code bellow:

StringBuilder filters = new StringBuilder();
filters.AppendFormat("{0}," Column2);
// ...and so on

myGridView.FilterDataFields = filters.ToString(); 
myGridView.FilteredDataSourcePropertyName = "FilterExpression";
myGridView.FilteredDataSourcePropertyFormat = "{1} like '{0}'"; // what is the proper expression to handle datetime ?

I replace the 'like' by '=' and it worked.

myGridView.FilteredDataSourcePropertyFormat = "{1} = '{0}'";

I found the solution here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.