Hi,
We are using GridDateTimeColumn of RadGrid to show date field. Everything works fine except "Equal to" filter of DateTime Column.
See the syntax for GridDateTimeColumn below
<telerik:GridDateTimeColumn FilterControlWidth="95px" HeaderText="Requested Date" Visible="true" ItemStyle-Width="200px"
DataField="RequestedDate" PickerType="DatePicker" SortExpression="RequestedDate" />
We are using the "2011.1.519.35" version of telerik and after googling, I found that the issue is fixed in the recent versions.
But we can't afford to upgrade the telerik at this point of time, as our site is on production.
Can you please suggest some alternative to fix this issue.
Thanks!!
We are using GridDateTimeColumn of RadGrid to show date field. Everything works fine except "Equal to" filter of DateTime Column.
See the syntax for GridDateTimeColumn below
<telerik:GridDateTimeColumn FilterControlWidth="95px" HeaderText="Requested Date" Visible="true" ItemStyle-Width="200px"
DataField="RequestedDate" PickerType="DatePicker" SortExpression="RequestedDate" />
We are using the "2011.1.519.35" version of telerik and after googling, I found that the issue is fixed in the recent versions.
But we can't afford to upgrade the telerik at this point of time, as our site is on production.
Can you please suggest some alternative to fix this issue.
Thanks!!
5 Answers, 1 is accepted
0
Hello Sheetal,
Generally, we recommend our users to upgrade to the latest major release version of RadControls so their projects would be up to date to any improvements and fixes. In your case we will need a very basic sample runnable web site demonstrating the problematic behavior. Thus, I will forward it to our developers to consider a possible work-around with the mentioned version.
Regards,
Eyup
Telerik
Generally, we recommend our users to upgrade to the latest major release version of RadControls so their projects would be up to date to any improvements and fixes. In your case we will need a very basic sample runnable web site demonstrating the problematic behavior. Thus, I will forward it to our developers to consider a possible work-around with the mentioned version.
Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Sheetal
Top achievements
Rank 1
answered on 17 Sep 2013, 02:03 PM
Hi,
Thanks for your reply.
I have created one PoC to replicate the issue.
Please see the code below.
ASPX code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<telerik:RadGrid ID="gridTest" runat="server" AllowPaging="True" Width="600px"
AllowFilteringByColumn="true" PageSize="10" AllowSorting="True" AutoGenerateColumns="false" GridLines="Vertical" >
<GroupingSettings CaseSensitive="false" />
<PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
<MasterTableView caption="Telerik Demo" summary="Telerik Demo to illustrate GridDateTimeColumn filtering issue.">
<Columns>
<telerik:GridDateTimeColumn FilterControlWidth="95px" HeaderText="Requested Date" Visible="true" ItemStyle-Width="200px"
DataField="RequestedDate" PickerType="DatePicker" SortExpression="RequestedDate" />
<telerik:GridBoundColumn HeaderText="Title" Visible="true" DataType="System.String" DataField="Title" UniqueName="Title" >
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="ShowStatus" UniqueName="TemplateColumn" AllowFiltering="false"
DataField="Status" >
<ItemTemplate>
<asp:LinkButton ID="linkStatus" runat="server" Text="Show Status" OnClientClick="javascript:alert('active');"></asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
</form>
</body>
</html>
ASPX.cs
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//RadGrid1.DataSource = GetData();
//RadGrid1.DataBind();
gridTest.DataSource = GetData();
gridTest.DataBind();
}
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Title");
dt.Columns.Add("RequestedDate", typeof(DateTime));
DataRow dr = null;
for (int i = 0; i < 10; i++)
{
dr = dt.NewRow();
dr["Title"] = "test " + i.ToString();
dr["RequestedDate"] = System.DateTime.Now.AddDays(i);
dt.Rows.Add(dr);
}
return dt;
}
}
Let me know if I can do something with this code without upgrading to latest telerik version.
Currently I am using "2011.1.519.35" Telerik version.
Thanks,
Sheetal
Thanks for your reply.
I have created one PoC to replicate the issue.
Please see the code below.
ASPX code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<telerik:RadGrid ID="gridTest" runat="server" AllowPaging="True" Width="600px"
AllowFilteringByColumn="true" PageSize="10" AllowSorting="True" AutoGenerateColumns="false" GridLines="Vertical" >
<GroupingSettings CaseSensitive="false" />
<PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
<MasterTableView caption="Telerik Demo" summary="Telerik Demo to illustrate GridDateTimeColumn filtering issue.">
<Columns>
<telerik:GridDateTimeColumn FilterControlWidth="95px" HeaderText="Requested Date" Visible="true" ItemStyle-Width="200px"
DataField="RequestedDate" PickerType="DatePicker" SortExpression="RequestedDate" />
<telerik:GridBoundColumn HeaderText="Title" Visible="true" DataType="System.String" DataField="Title" UniqueName="Title" >
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="ShowStatus" UniqueName="TemplateColumn" AllowFiltering="false"
DataField="Status" >
<ItemTemplate>
<asp:LinkButton ID="linkStatus" runat="server" Text="Show Status" OnClientClick="javascript:alert('active');"></asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
</form>
</body>
</html>
ASPX.cs
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//RadGrid1.DataSource = GetData();
//RadGrid1.DataBind();
gridTest.DataSource = GetData();
gridTest.DataBind();
}
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Title");
dt.Columns.Add("RequestedDate", typeof(DateTime));
DataRow dr = null;
for (int i = 0; i < 10; i++)
{
dr = dt.NewRow();
dr["Title"] = "test " + i.ToString();
dr["RequestedDate"] = System.DateTime.Now.AddDays(i);
dt.Rows.Add(dr);
}
return dt;
}
}
Let me know if I can do something with this code without upgrading to latest telerik version.
Currently I am using "2011.1.519.35" Telerik version.
Thanks,
Sheetal
0
Hi Sheetal,
Please note that using DataBind() is not recommended. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, 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
Please make the suggested modification and let me know about the result.
Regards,
Eyup
Telerik
Please note that using DataBind() is not recommended. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, 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
Please make the suggested modification and let me know about the result.
Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Sandeep
Top achievements
Rank 1
answered on 11 Oct 2013, 10:23 AM
Hi,
I have made some changes in my POC below is the code.
ASPX page -
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<telerik:RadGrid ID="gridTest" runat="server" AllowPaging="True" Width="600px"
AllowFilteringByColumn="true" PageSize="10" AllowSorting="True"
AutoGenerateColumns="false" GridLines="Vertical" EnableLinqExpressions ="false"
onitemcommand="gridTest_ItemCommand"
onneeddatasource="gridTest_NeedDataSource" >
<GroupingSettings CaseSensitive="false" />
<PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
<MasterTableView caption="Telerik Demo" summary="Telerik Demo to illustrate GridDateTimeColumn filtering issue.">
<Columns>
<telerik:GridDateTimeColumn FilterControlWidth="95px" HeaderText="Requested Date" Visible="true" ItemStyle-Width="200px"
DataField="RequestedDate" PickerType="DateTimePicker" SortExpression="RequestedDate" />
<telerik:GridBoundColumn HeaderText="Title" Visible="true" DataType="System.String" DataField="Title" UniqueName="Title" >
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="ShowStatus" UniqueName="TemplateColumn" AllowFiltering="false"
DataField="Status" DataType="System.Boolean" >
<ItemTemplate>
<asp:LinkButton ID="linkStatus" runat="server" Text="Show Status" OnClientClick="javascript:alert('active');"></asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</form>
</body>
</html>
ASPX.cs page -
namespace TelerikGridDemo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//gridTest.DataSource = GetData();
//gridTest.DataBind();
}
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Title");
dt.Columns.Add("RequestedDate", typeof(DateTime));
DataRow dr = null;
for (int i = 0; i < 10; i++)
{
dr = dt.NewRow();
dr["Title"] = "test " + i.ToString();
dr["RequestedDate"] = System.DateTime.Now.AddDays(i);
dt.Rows.Add(dr);
}
return dt;
}
protected void gridTest_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
gridTest.DataSource = GetData();
if (Session["filterPattern"] != null)
{
gridTest.MasterTableView.FilterExpression = (string)Session["filterPattern"];
}
}
protected void gridTest_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName &&
((Pair)e.CommandArgument).Second.ToString() == "RequestedDate"
&& ((Pair)e.CommandArgument).First.ToString() != "NoFilter")
{
e.Canceled = true;
GridFilteringItem filterItem = (GridFilteringItem)e.Item;
string currentPattern = (filterItem[((Pair)e.CommandArgument).Second.ToString()].Controls[0] as RadDatePicker).SelectedDate.ToString();
string filterPattern = "";
string filterPatternAssist = "";
if (currentPattern.IndexOf(" ") != -1)
{
currentPattern = currentPattern.Replace(" ", "/");
}
string[] vals = currentPattern.Split("/".ToCharArray());
string filterOption = (e.CommandArgument as Pair).First.ToString();
if (filterOption != "IsNull" && filterOption != "NotIsNull")
{
if (vals.Length > 3)
{
filterPatternAssist = vals[4] + "/" + vals[3];// + "/" + vals[5];
}
filterPattern = vals[1] + "/" + vals[0] + "/" + vals[2];
filtVal = filterPattern;
}
GridBoundColumn dateColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("RequestedDate");
switch (filterOption)
{
case "EqualTo":
filterPattern = "[RequestedDate] = '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.EqualTo;
break;
case "NotEqualTo":
filterPattern = "Not [RequestedDate] = '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.NotEqualTo;
break;
case "GreaterThan":
filterPattern = "[RequestedDate] > '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.GreaterThan;
break;
case "LessThan":
filterPattern = "[RequestedDate] < '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.LessThan;
break;
case "GreaterThanOrEqualTo":
filterPattern = "[RequestedDate] >= '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.GreaterThanOrEqualTo;
break;
case "LessThanOrEqualTo":
filterPattern = "[RequestedDate] <= '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.LessThanOrEqualTo;
break;
case "Between":
filterPattern = "'" + filterPattern + "' <= [RequestedDate] AND [RequestedDate] <= '" + filterPatternAssist + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.Between;
break;
case "NotBetween":
filterPattern = "[RequestedDate] <= '" + filterPattern + "' OR [RequestedDate] >= '" + filterPatternAssist + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.NotBetween;
break;
case "IsNull":
break;
case "NotIsNull":
break;
default:
break;
}
foreach (GridColumn column in gridTest.MasterTableView.Columns)
{
if (column.UniqueName != "RequestedDate")
{
column.CurrentFilterFunction = GridKnownFunction.NoFilter;
column.CurrentFilterValue = string.Empty;
}
}
Session["filterPattern"] = filterPattern;
dateColumn.CurrentFilterValue = currentPattern;
filterItem.OwnerTableView.Rebind();
}
//Add more conditional checks for commands here if necessary
else if (e.CommandName != RadGrid.SortCommandName && e.CommandName != RadGrid.PageCommandName)
{
Session["filterPattern"] = null;
GridBoundColumn dateColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("RequestedDate");
dateColumn.CurrentFilterFunction = GridKnownFunction.NoFilter;
dateColumn.CurrentFilterValue = string.Empty;
}
}
}
}
The above code is throwing parse exception at "filterItem.OwnerTableView.Rebind();" line.
If i add EnableLinqExpressions ="false" in my aspx page for radgrid the exception changes to System.FormatException: The string was not recognized as a valid DateTime.
Please let us know what could be the cause for the cause for the exception.
Thanks,
Sheetal
I have made some changes in my POC below is the code.
ASPX page -
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<telerik:RadGrid ID="gridTest" runat="server" AllowPaging="True" Width="600px"
AllowFilteringByColumn="true" PageSize="10" AllowSorting="True"
AutoGenerateColumns="false" GridLines="Vertical" EnableLinqExpressions ="false"
onitemcommand="gridTest_ItemCommand"
onneeddatasource="gridTest_NeedDataSource" >
<GroupingSettings CaseSensitive="false" />
<PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />
<MasterTableView caption="Telerik Demo" summary="Telerik Demo to illustrate GridDateTimeColumn filtering issue.">
<Columns>
<telerik:GridDateTimeColumn FilterControlWidth="95px" HeaderText="Requested Date" Visible="true" ItemStyle-Width="200px"
DataField="RequestedDate" PickerType="DateTimePicker" SortExpression="RequestedDate" />
<telerik:GridBoundColumn HeaderText="Title" Visible="true" DataType="System.String" DataField="Title" UniqueName="Title" >
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="ShowStatus" UniqueName="TemplateColumn" AllowFiltering="false"
DataField="Status" DataType="System.Boolean" >
<ItemTemplate>
<asp:LinkButton ID="linkStatus" runat="server" Text="Show Status" OnClientClick="javascript:alert('active');"></asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</form>
</body>
</html>
ASPX.cs page -
namespace TelerikGridDemo
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//gridTest.DataSource = GetData();
//gridTest.DataBind();
}
private DataTable GetData()
{
DataTable dt = new DataTable();
dt.Columns.Add("Title");
dt.Columns.Add("RequestedDate", typeof(DateTime));
DataRow dr = null;
for (int i = 0; i < 10; i++)
{
dr = dt.NewRow();
dr["Title"] = "test " + i.ToString();
dr["RequestedDate"] = System.DateTime.Now.AddDays(i);
dt.Rows.Add(dr);
}
return dt;
}
protected void gridTest_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
gridTest.DataSource = GetData();
if (Session["filterPattern"] != null)
{
gridTest.MasterTableView.FilterExpression = (string)Session["filterPattern"];
}
}
protected void gridTest_ItemCommand(object sender, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.FilterCommandName &&
((Pair)e.CommandArgument).Second.ToString() == "RequestedDate"
&& ((Pair)e.CommandArgument).First.ToString() != "NoFilter")
{
e.Canceled = true;
GridFilteringItem filterItem = (GridFilteringItem)e.Item;
string currentPattern = (filterItem[((Pair)e.CommandArgument).Second.ToString()].Controls[0] as RadDatePicker).SelectedDate.ToString();
string filterPattern = "";
string filterPatternAssist = "";
if (currentPattern.IndexOf(" ") != -1)
{
currentPattern = currentPattern.Replace(" ", "/");
}
string[] vals = currentPattern.Split("/".ToCharArray());
string filterOption = (e.CommandArgument as Pair).First.ToString();
if (filterOption != "IsNull" && filterOption != "NotIsNull")
{
if (vals.Length > 3)
{
filterPatternAssist = vals[4] + "/" + vals[3];// + "/" + vals[5];
}
filterPattern = vals[1] + "/" + vals[0] + "/" + vals[2];
filtVal = filterPattern;
}
GridBoundColumn dateColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("RequestedDate");
switch (filterOption)
{
case "EqualTo":
filterPattern = "[RequestedDate] = '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.EqualTo;
break;
case "NotEqualTo":
filterPattern = "Not [RequestedDate] = '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.NotEqualTo;
break;
case "GreaterThan":
filterPattern = "[RequestedDate] > '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.GreaterThan;
break;
case "LessThan":
filterPattern = "[RequestedDate] < '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.LessThan;
break;
case "GreaterThanOrEqualTo":
filterPattern = "[RequestedDate] >= '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.GreaterThanOrEqualTo;
break;
case "LessThanOrEqualTo":
filterPattern = "[RequestedDate] <= '" + filterPattern + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.LessThanOrEqualTo;
break;
case "Between":
filterPattern = "'" + filterPattern + "' <= [RequestedDate] AND [RequestedDate] <= '" + filterPatternAssist + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.Between;
break;
case "NotBetween":
filterPattern = "[RequestedDate] <= '" + filterPattern + "' OR [RequestedDate] >= '" + filterPatternAssist + "'";
dateColumn.CurrentFilterFunction = GridKnownFunction.NotBetween;
break;
case "IsNull":
break;
case "NotIsNull":
break;
default:
break;
}
foreach (GridColumn column in gridTest.MasterTableView.Columns)
{
if (column.UniqueName != "RequestedDate")
{
column.CurrentFilterFunction = GridKnownFunction.NoFilter;
column.CurrentFilterValue = string.Empty;
}
}
Session["filterPattern"] = filterPattern;
dateColumn.CurrentFilterValue = currentPattern;
filterItem.OwnerTableView.Rebind();
}
//Add more conditional checks for commands here if necessary
else if (e.CommandName != RadGrid.SortCommandName && e.CommandName != RadGrid.PageCommandName)
{
Session["filterPattern"] = null;
GridBoundColumn dateColumn = (GridBoundColumn)e.Item.OwnerTableView.GetColumnSafe("RequestedDate");
dateColumn.CurrentFilterFunction = GridKnownFunction.NoFilter;
dateColumn.CurrentFilterValue = string.Empty;
}
}
}
}
The above code is throwing parse exception at "filterItem.OwnerTableView.Rebind();" line.
If i add EnableLinqExpressions ="false" in my aspx page for radgrid the exception changes to System.FormatException: The string was not recognized as a valid DateTime.
Please let us know what could be the cause for the cause for the exception.
Thanks,
Sheetal
0
Hi Sheetal,
Please try to remove the following lines from the NeedDataSource event handler:
If the issue remains, please 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 suggest a proper solution.
Regards,
Eyup
Telerik
Please try to remove the following lines from the NeedDataSource event handler:
if
(Session[
"filterPattern"
] !=
null
)
{
gridTest.MasterTableView.FilterExpression = (
string
)Session[
"filterPattern"
];
}
If the issue remains, please 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 suggest a proper solution.
Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.