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

GridDateTimeColumn filtering problem

2 Answers 191 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 2
Marco asked on 26 Aug 2014, 11:58 AM
Hi to all,

I'm trying to use the basic filtering of the grid but in my GridDateTimeColumn i'm getting this error when trying to filter the column:

The argument types 'Edm.DateTimeOffset' and 'Edm.String' are incompatible for this operation. Near greater than or equals expression, line 6, column 21.

Here is my code:

HTML

<%@ Page Title="Logs" Language="C#" MasterPageFile="~/Platform/Site.Platform.Master" AutoEventWireup="true" CodeBehind="LogsList.aspx.cs" Inherits="UI.LogsList" %>

<asp:Content ID="HeaderContent" ContentPlaceHolderID="HeaderContent" runat="server">
</asp:Content>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
    <div style="height: 50px;">
        <asp:Label runat="server" ID="LabelPageTitle" CssClass="h3 GridTitle">Logs</asp:Label>
    </div>
    <div>
        <!-- Define the datasource -->
        <ef:EntityDataSource ID="EntityDataSourceLogs" runat="server" ContextTypeName="Common.EntityModels.PlatformDB" ConnectionString="name=PlatformDB"
            DefaultContainerName="PlatformDB"
            EnableUpdate="False" EnableDelete="False" EnableInsert="False"
            EntitySetName="Logs" OrderBy="it.CreatedDateTime desc" />
        <!-- Define the grid -->
        <telerik:RadGrid runat="server" ID="RadGridLogs" AllowPaging="True" AllowSorting="true" Height="578" DataSourceID="EntityDataSourceLogs">
            <GroupingSettings CaseSensitive="false"></GroupingSettings>
            <MasterTableView DataKeyNames="Id" AutoGenerateColumns="False" AllowPaging="true"
                AllowAutomaticInserts="false" ClientDataKeyNames="Id" AllowFilteringByColumn="true" >
                <Columns>
                    <telerik:GridBoundColumn DataField="Id" HeaderText="Id" SortExpression="Id" UniqueName="Id" Visible="false" MaxLength="100">
                    </telerik:GridBoundColumn>
                    <telerik:GridDateTimeColumn DataField="CreatedDateTime" HeaderText="Date" SortExpression="CreatedDateTime" Visible="true" MaxLength="50" ItemStyle-Width="50" FilterControlWidth="150px" PickerType="DatePicker" DataFormatString="{0:d}" AutoPostBackOnFilter="true" CurrentFilterFunction="GreaterThanOrEqualTo" ShowFilterIcon="false" EnableTimeIndependentFiltering="true">
                    </telerik:GridDateTimeColumn>

                    <telerik:GridBoundColumn DataField="Description" HeaderText="Description" SortExpression="Description" UniqueName="Description" Visible="true" MaxLength="100" ItemStyle-Width="100" FilterControlWidth="300px" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" >
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Server" HeaderText="Server" SortExpression="Server" UniqueName="Server" Visible="true" MaxLength="50" ItemStyle-Width="50" FilterControlWidth="150px" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" >
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Application" HeaderText="Application" SortExpression="Application" UniqueName="Application" Visible="true" MaxLength="50" ItemStyle-Width="50" FilterControlWidth="150px" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" >
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Module" HeaderText="Module" SortExpression="Module" UniqueName="Module" Visible="true" MaxLength="50" ItemStyle-Width="50" FilterControlWidth="150px" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" >
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Function" HeaderText="Function" SortExpression="Function" UniqueName="Function" Visible="true" MaxLength="50" ItemStyle-Width="50" FilterControlWidth="150px" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" >
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings EnableRowHoverStyle="true">
                <Selecting AllowRowSelect="False"></Selecting>
                <Scrolling AllowScroll="True" UseStaticHeaders="True" />
            </ClientSettings>
            <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" Position="Bottom" PageSizeControlType="RadComboBox"></PagerStyle>
        </telerik:RadGrid>
    </div>
</asp:Content>

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UI
{
    public partial class LogsList : DetailBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}


The entity value of the field is:

namespace Common.EntityModels
{
    using System;
    using System.Collections.Generic;
    
    public partial class Log
    {
        public long Id { get; set; }
        public System.DateTimeOffset CreatedDateTime { get; set; }
        public short Type { get; set; }
        public string Description { get; set; }
        public string Server { get; set; }
        public string Application { get; set; }
        public string Module { get; set; }
        public string Function { get; set; }
        public Nullable<int> TenantId { get; set; }
        public Nullable<int> UserId { get; set; }
        public string SessionId { get; set; }
    }
}


And in SQL is:

[CreatedDateTime]   DATETIMEOFFSET (7)  NOT NULL

Can you tell me what i'm doing wrong??

Thanks.




2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Aug 2014, 03:36 AM
Hi Marco,

Can you please try setting EnableLinqExpressions to false for your grid and check if it helps.

ASPX:
<telerik:RadGrid D="rgrdSample" runat="server" EnableLinqExpressions="false">

Thanks,
Princy
0
Marco
Top achievements
Rank 2
answered on 28 Aug 2014, 12:15 PM
There is no solution for the DateTimeOffset because is not superted as a data type

                    <telerik:GridDateTimeColumn DataField="CreatedDateTime" HeaderText="Date" SortExpression="CreatedDateTime" Visible="true" MaxLength="50" ItemStyle-Width="50" FilterControlWidth="150px" PickerType="DatePicker" DataFormatString="{0:g}" AutoPostBackOnFilter="true" CurrentFilterFunction="GreaterThanOrEqualTo" ShowFilterIcon="false" EnableTimeIndependentFiltering="true" DataType="System.DateTime">
                    </telerik:GridDateTimeColumn>

I did this in the backend and it is a work arround:

using Common.EntityModels;
using Common.Tools;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace UI
{
    public partial class LogsList : DetailBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void RadGridLogs_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            using (var tDBContext = new PlatformDB())
            {
                //Get the object.
                var tLogs = (from tL in tDBContext.Logs
                             from tT in tDBContext.Tenants.Where(tT => tT.Id == tL.TenantId).DefaultIfEmpty()
                             from tU in tDBContext.Users.Where(tU => tU.Id == tL.UserId).DefaultIfEmpty()
                             select new
                             {
                                 Id = tL.Id,
                                 CreatedDateTime = tL.CreatedDateTime,
                                 Description = tL.Description,
                                 Server = tL.Server,
                                 Application = tL.Application,
                                 Module = tL.Module,
                                 Function = tL.Function,
                                 Type = tL.Type,
                                 Tenant = (tL.TenantId != null) ? tT.Name : string.Empty,
                                 User = (tL.UserId != null) ? tU.Name : string.Empty,
                             }).OrderByDescending(s => s.CreatedDateTime);

                //Set the data table.
                DataTable tDataTable = new DataTable();
                tDataTable.Columns.Add("Id", typeof(long));
                tDataTable.Columns.Add("CreatedDateTime", typeof(DateTime));
                tDataTable.Columns.Add("Description", typeof(String));
                tDataTable.Columns.Add("Server", typeof(String));
                tDataTable.Columns.Add("Application", typeof(String));
                tDataTable.Columns.Add("Module", typeof(String));
                tDataTable.Columns.Add("Function", typeof(String));
                tDataTable.Columns.Add("Type", typeof(string));
                tDataTable.Columns.Add("TenantId", typeof(string));
                tDataTable.Columns.Add("UserId", typeof(string));

                //Fill data table.
                foreach (var tLog in tLogs)
                {
                    var tRow = tDataTable.NewRow();
                    tRow["Id"] = tLog.Id;
                    tRow["CreatedDateTime"] = tLog.CreatedDateTime.DateTime;
                    tRow["Description"] = tLog.Description;
                    tRow["Server"] = tLog.Server;
                    tRow["Application"] = tLog.Application;
                    tRow["Module"] = tLog.Module;
                    tRow["Function"] = tLog.Function;
                    tRow["Type"] = GetPlatformTypeText(typeof(PlatformTypes.LogType), tLog.Type.ToString());
                    tRow["TenantId"] = tLog.Tenant;
                    tRow["UserId"] = tLog.User;
                    tDataTable.Rows.Add(tRow);
                }

                this.RadGridLogs.DataSource = tDataTable;
            }
        }
Tags
Filter
Asked by
Marco
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Marco
Top achievements
Rank 2
Share this question
or