The error I'm getting if trying to use the direct filter expression is:
"LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method, and this method cannot be translated into a store expression."
I'll include the code that I'm using below as well.
Thanks so much,
Kevin
Dashboard.aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="dashboard.aspx.cs" Inherits="SearchDesk.billing.Dashboard" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadGrid Width="700px" runat="server" ID="gridActions" OnItemDataBound="GridActionsItemDataBound"
OnNeedDataSource="GridActionsNeedDataSource" AutoGenerateColumns="False" OnItemCommand="getitem"
AllowPaging="True" GridLines="None" Skin="Windows7" OnSortCommand="gridActionSort"
AllowFilteringByColumn="True" AllowSorting="True" CellSpacing="0">
<FilterMenu EnableImageSprites="False"></FilterMenu>
<HeaderContextMenu EnableAutoScroll="True">
</HeaderContextMenu>
<MasterTableView PageSize="2" CommandItemDisplay="Top" DataKeyNames="ActionID">
<CommandItemSettings ShowAddNewRecordButton="false" ></CommandItemSettings>
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn AllowFiltering="false" AutoPostBackOnFilter="false" AllowSorting="false" DataField="ActionTypeID" Visible="false" UniqueName="ActionTypeID"></telerik:GridBoundColumn>
<telerik:griddateTimeColumn DataFormatString="{0:MM/dd/yyyy}" AllowFiltering="true" AllowSorting="true" DataField="ActionDate" HeaderText="Action Date" UniqueName="ActionDate"></telerik:griddateTimeColumn>
<telerik:GridBoundColumn AllowFiltering="true" AutoPostBackOnFilter="true" AllowSorting="true" DataField="SearchID" HeaderText="Search Number" UniqueName="SearchID"></telerik:GridBoundColumn>
<telerik:GridBoundColumn AllowFiltering="true" AutoPostBackOnFilter="true" AllowSorting="true" DataField="tExpenseType.ExpenseType" HeaderText="Expense Type" UniqueName="ExpenseType"></telerik:GridBoundColumn>
<telerik:GridTemplateColumn AllowFiltering="false" UniqueName="buttons" HeaderText="Actions" ItemStyle-Width="200">
<ItemTemplate>
<asp:Panel runat="server" ID="CreateInvoice" Visible="false">
<asp:ImageButton runat="server" ID="button1" Height="16" Width="16" ImageUrl="~/Images/newIcon.jpg" title="Create New Invoice" AlternateText="Create New Invoice" PostBackUrl='<%# "~/CreateNew.aspx?AID=" + DataBinder.Eval(Container.DataItem,"ActionID") %>' />
</asp:Panel>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
</div>
</form>
</body>
</html>
Backend aspx.cs page:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SearchDeskEntityFrameworkDAL;
using SearchDeskEntityFrameworkDAL.Repositories;
using Telerik.Web.UI;
using System.Linq.Dynamic;
namespace SearchDesk.billing
{
public partial class Dashboard : SearchDesk.BasePage
{
private string sortActions;
private DateTime filterDateTime;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridActionsItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
var item = (GridDataItem)e.Item;
int actionTypeID = Convert.ToInt16(item["ActionTypeID"].Text);
if (actionTypeID == (int)ActionTypes.CreateInvoice)
{
item["buttons"].Controls[1].Visible = true;
}
}
}
protected void GridActionsNeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
var searchDeskBillingRepository = new SearchDeskBillingRepository();
var filter = gridActions.MasterTableView.FilterExpression;
if (string.IsNullOrEmpty(sortActions))
{
sortActions = "ActionDate";
}
if (string.IsNullOrEmpty(filter))
{
gridActions.DataSource =
searchDeskBillingRepository.GetActionsAssignedToUser(CurrentUser.ObjectID).OrderBy(sortActions);
}
else
{
filter = filter.Replace(".ToString()", "");
if (filter.Contains("DateTime.Parse"))
{
gridActions.DataSource =
searchDeskBillingRepository.GetActionsAssignedToUser(CurrentUser.ObjectID).Where(
s => s.ActionDate == filterDateTime);
}
else
{
gridActions.DataSource =
searchDeskBillingRepository.GetActionsAssignedToUser(CurrentUser.ObjectID).Where(filter);
}
}
}
public override string PageName
{
get { return "DashBoard.aspx"; }
}
protected void gridActionSort(object sender, GridSortCommandEventArgs e)
{
if (e.NewSortOrder == GridSortOrder.None)
{
sortActions = e.SortExpression;
}
else
{
sortActions = e.SortExpression + " " + e.NewSortOrder;
}
}
protected void getitem(object sender, GridCommandEventArgs e)
{
if (e.Item is GridFilteringItem){
GridFilteringItem filteringItem = e.Item as GridFilteringItem;
filterDateTime = Convert.ToDateTime(((RadDatePicker)filteringItem["ActionDate"].Controls[0]).DbSelectedDate);
}
}
}
}