我正在尝试过滤网格中同一列中的两个不同的(数据选择器)。我尝试使用这两个字段来达到一个命令。整个过滤过程在后面的代码中进行,到目前为止它正在为网格中的其他字段工作。但对于一个我得到一个奇怪的例外:
{“参数类型 'Edm.DateTime' 和 'Edm.String' 与此操作不兼容。接近大于或等于表达式,第 6 行,第 15 列。”}
在数据库中,该字段是一个日期时间,它是一个单列
我的代码:
<telerik:GridBoundColumn DataField="EntryDate" DataType="System.DateTime" DataFormatString="{0:dd/MM/yyyy}" FilterControlAltText="Filter EntryDate column"
HeaderText="Date" SortExpression="EntryDate" UniqueName="EntryDate" FilterControlWidth="50px">
<FilterTemplate>
From
<telerik:RadDatePicker ID="FromOrderDatePicker" runat="server" Width="100px" AutoPostBack="true"
OnSelectedDateChanged="FromOrderDatePicker_SelectedDateChanged" OnPreRender="FromOrderDatePicker_PreRender" />
to
<telerik:RadDatePicker ID="ToOrderDatePicker" runat="server" Width="100px" AutoPostBack="true"
OnSelectedDateChanged="ToOrderDatePicker_SelectedDateChanged" OnPreRender="ToOrderDatePicker_PreRender" />
</FilterTemplate>
</telerik:GridBoundColumn>
后面的代码:
protected void FromOrderDatePicker_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)
{
RadDatePicker picker = sender as RadDatePicker;
ViewState["FromDatePicker"] = DateTimeToString(picker.SelectedDate.Value);
ExpressionChanged();
}
protected void FromOrderDatePicker_PreRender(object sender, EventArgs e)
{
if (ViewState["FromDatePicker"] != null)
{
RadDatePicker picker = sender as RadDatePicker;
picker.SelectedDate = StringToDateTime(ViewState["FromDatePicker"].ToString());
}
}
private string DateTimeToString(DateTime dt)
{
return dt.Month + "/" + dt.Day + "/" + dt.Year;
}
private DateTime StringToDateTime(string s)
{
string[] dts = s.Split('/');
DateTime dt = new DateTime(Int32.Parse(dts[2]), Int32.Parse(dts[0]), Int32.Parse(dts[1]));
return dt;
}
发布代码只是多余的(对于 toDatePicker)
private void ExpressionChanged()
{
//reset
TimeReportGrid.MasterTableView.FilterExpression = null;
TimeReportGrid.MasterTableView.Rebind();
if (ViewState["FromDatePicker"] != null &&
ViewState["ToDatePicker"] != null &&
ViewState["FromDatePicker"].ToString() != "" &&
ViewState["ToDatePicker"].ToString() != "")
{
TimeReportGrid.MasterTableView.FilterExpression += "(it.EntryDate >= '" + ViewState["FromDatePicker"].ToString() + "') AND (it.EntryDate <= '" + ViewState["ToDatePicker"].ToString() + "')";
}
随时询问是否有任何问题
感谢您的帮助和快速答复!