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

Error while filtering data by DateTimeColumn

6 Answers 318 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tushar
Top achievements
Rank 1
Tushar asked on 27 Aug 2014, 09:38 AM
Hi,
I am using two Rad grids on one of my page. There are some DateTimeColumns created for each of them for DateTime fields. Dates are displayed correctly in DateTime column. 
When I apply filter on DateTime column, it works in one grid but throws exception in another grid, although code is same for both. There is no custom filtering.

For both grids, DateTimeColumn is added programmatically as below:
-------------------------------------------------------------------------------------------------------------------------
GridDateTimeColumn boundColumn = new GridDateTimeColumn();

ProductsGrid.MasterTableView.Columns.Add(boundColumn);
boundColumn.PickerType = GridDateTimeColumnPickerType.DatePicker;
boundColumn.FilterControlWidth = Unit.Pixel(100);
boundColumn.HeaderStyle.Width = Unit.Pixel(110);
boundColumn.DataField = col.SystemName;
boundColumn.UniqueName = col.SystemName;
boundColumn.EnableTimeIndependentFiltering = true;
boundColumn.HeaderText = col.FriendlyName;
boundColumn.DataFormatString = "{0:dd/MM/yyyy}";
boundColumn.AutoPostBackOnFilter = true;
boundColumn.SortExpression = col.SystemName;

boundColumn.CurrentFilterFunction = GridKnownFunction.GreaterThanOrEqualTo;
boundColumn.ShowFilterIcon = true;

boundColumn.Display = col.Visible;
-------------------------------------------------------------------------------------------------------------------------

Exception I am getting while filtering by DateTime Column is :

-------------------------------------------------------------------------------------------------------------------------
Exception Type: Telerik.Web.UI.ParseException

Message: Neither of the types 'String' and 'DateTime' converts to the other

Stack Trace:
at
Telerik.Web.UI.ExpressionParser.GenerateConditional(Expression test,
Expression expr1, Expression expr2, Int32 errorPos)

at Telerik.Web.UI.ExpressionParser.ParseIif()

at Telerik.Web.UI.ExpressionParser.ParseIdentifier()

at Telerik.Web.UI.ExpressionParser.ParsePrimaryStart()

at Telerik.Web.UI.ExpressionParser.ParsePrimary()

at Telerik.Web.UI.ExpressionParser.ParseUnary()

at Telerik.Web.UI.ExpressionParser.ParseMultiplicative()

at Telerik.Web.UI.ExpressionParser.ParseAdditive()

at Telerik.Web.UI.ExpressionParser.ParseComparison()

at Telerik.Web.UI.ExpressionParser.ParseLogicalAnd()

at Telerik.Web.UI.ExpressionParser.ParseLogicalOr()

at Telerik.Web.UI.ExpressionParser.ParseExpression()

at Telerik.Web.UI.ExpressionParser.ParseParenExpression()

at Telerik.Web.UI.ExpressionParser.ParsePrimaryStart()

at Telerik.Web.UI.ExpressionParser.ParsePrimary()

at Telerik.Web.UI.ExpressionParser.ParseUnary()

at Telerik.Web.UI.ExpressionParser.ParseMultiplicative()

at Telerik.Web.UI.ExpressionParser.ParseAdditive()

at Telerik.Web.UI.ExpressionParser.ParseComparison()

at Telerik.Web.UI.ExpressionParser.ParseLogicalAnd()

at Telerik.Web.UI.ExpressionParser.ParseLogicalOr()

at Telerik.Web.UI.ExpressionParser.ParseExpression()

at Telerik.Web.UI.ExpressionParser.Parse(Type resultType)

at Telerik.Web.UI.DynamicExpression.ParseLambda(ParameterExpression[]
parameters, Type resultType, String expression, Object[] values)

at Telerik.Web.UI.DynamicExpression.ParseLambda(Type itType, Type resultType,
String expression, Object[] values)

at Telerik.Web.UI.GridDynamicQueryable.Where(IQueryable source, String
predicate, Object[] values)

at Telerik.Web.UI.GridDataTableFromEnumerable.FillData35()

at Telerik.Web.UI.GridDataTableFromEnumerable.FillData()

at Telerik.Web.UI.GridResolveEnumerable.Initialize()

at Telerik.Web.UI.GridResolveEnumerable.EnsureInitialized()

at Telerik.Web.UI.GridResolveEnumerable.get_DataTable()

at Telerik.Web.UI.GridEnumerableFromDataView..ctor(GridTableView owner,
IEnumerable enumerable, Boolean CaseSensitive, Boolean autoGenerateColumns,
GridColumnCollection presentColumns, String[] additionalField, Boolean
retrieveAllFields, Boolean enableSplitHeaderText)

at Telerik.Web.UI.GridDataSourceHelper.CreateGridEnumerable(GridTableView
owner, IEnumerable enumerable, Boolean caseSensitive, Boolean
autoGenerateColumns, GridColumnCollection presentColumns, String[]
additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText)

at Telerik.Web.UI.GridDataSourceHelper.GetResolvedDataSource(GridTableView
owner, Object dataSource, String dataMember, Boolean caseSensitive, Boolean
autoGenerateColumns, GridColumnCollection presentColumns, String[]
additionalField, Boolean retrieveAllFields, Boolean enableSplitHeaderText)

at Telerik.Web.UI.GridTableView.get_ResolvedDataSource()

at Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource)

at Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource,
Boolean useDataSource)

at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable
data)

at
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable
data)

at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments,
DataSourceViewSelectCallback callback)

at System.Web.UI.WebControls.DataBoundControl.PerformSelect()

at Telerik.Web.UI.GridTableView.PerformSelect()

at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()

at Telerik.Web.UI.GridTableView.DataBind()

at Telerik.Web.UI.GridTableView.Rebind()

at Telerik.Web.UI.GridFilterCommandEventArgs.ExecuteCommand(Object source)

at Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e)

at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)

at Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e)

at System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)

at Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e)

at Telerik.Web.UI.GridItem.FireCommandEvent(String commandName, Object
commandArgument)

at Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,
String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)

at System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

-------------------------------------------------------------------------------------------------------------------------

Can someone please let me know the reason for this exception?

Best Regards
Tushar

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Aug 2014, 10:27 AM

Hi Tushar,

Can you make sure that the column you are trying to bind is a DateTime column. Try setting EnableLinqExpressions to false and also set FilterDateFormat for the DateTimeColumn. If this doesn't help, provide your full code snippet.

C#:

ProductsGrid.EnableLinqExpressions = false;
. . .
boundColumn.FilterDateFormat = "dd/MM/yyyy";

Thanks,
Shinu

0
Tushar
Top achievements
Rank 1
answered on 27 Aug 2014, 01:17 PM
Thanks Shinu for quick response!!
It did work after setting EnableLinqExpressions to false and FilterDateFormat.

But why do I need to set EnableLinqExpressions to false? My export functionality uses grid filter expression and is breaking because of this change.

0
Tushar
Top achievements
Rank 1
answered on 27 Aug 2014, 01:18 PM
Thanks Shinu for quick response!!
It did work after setting EnableLinqExpressions to false and FilterDateFormat.

But why do I need to set EnableLinqExpressions to false? My export functionality uses grid filter expression and is breaking because of this change.

0
Shinu
Top achievements
Rank 2
answered on 28 Aug 2014, 03:46 AM
Hi Tushar,

Setting EnableLinqExpressions to false is required for filtering grid which is bound to a DataTable. The default value of this property is true, so you would not have to set it if you use LinqDataSource for example. When the LINQ expressions of the RadGrid are enabled, the performance is significantly improved because the grid uses dynamic LINQ expressions for all data operations. However, this leads to some limitations and that is why theEnableLinqExpressions property is provided. It is fine to bind to a DataTable and not set EnableLinqExpressions="false" as long as you do not perform manual filtering that requires T-SQL syntax.

Thanks,
Shinu
0
Tushar
Top achievements
Rank 1
answered on 28 Aug 2014, 09:26 AM
Hi Shinu,
But my grid is not bound to datatable, it is bound to list of model objects. Some more observations:
1. Columns other than DateTime column are filtering successfully with default EnableLinqExpressions
2. All Columns including DateTime column are filtering successfully with EnableLinqExpressions=False
3. My other grid is similarly bound to list of obects and DateTime column filtering is working fine for it without EnableLinqExpressions = false.

Can there be any other setting that is affecting DateTimeColumn filter?

Thanks!!



0
Eyup
Telerik team
answered on 02 Sep 2014, 06:34 AM
Hi Tushar,

When creating a RadGrid programmatically, please make sure that you are closely following the steps provided in this article:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section22


Also, can you verify that you are not using DataBind() to bind the grid? Please note that performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding


If you are already using these directions and the problem persists, I suggest that you open a formal support ticket and send us a very basic runnable web site demonstrating the problematic behavior. Thus, we will be able to further debug and analyze the project and try to determine the cause of the issue.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Tushar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tushar
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or