New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Filter GridBoundColumn of Type DateTime

If you prefer not to handle the filtering manually as stated below, consider using built-in GridDateTimeColumn as shown in this online demo.

When you choose to apply filtering for bound grid column of type DateTime, Telerik RadGrid will filter the records in the corresponding column by fetching the user entry from the filter box in the following format - mm/dd/yyyy. However, forcing the user to type the date in this format is not intuitive as the dates are displayed differently in the column cells. Therefore, you you may want to let the user type the same date format as previously specified through the DataFormatString of the column.In such case you will need to cancel the default filter action and modify the filter string accordingly to make it "automatically recognizable" by the grid. For this purpose you will need to modify the FilterExpression (see this topic for more info) of the grid accordingly after reformatting the pattern entered in the column filter box.The sample implementation listed below shows how this can be done when you choose the following DateTime format - dd/MM/yyyy. With this approach the filter criteria will be retained on paging/sorting operation. Note, however, the OrderDate column will be filtered "separately" from the rest of the grid columns, meaning that:

  • the filters for the other columns in the grid will be cleared when you choose filter pattern for the OrderDate column

  • the OrderDate column filter will be cleared when you specify filter for some other column

For more details review the forthcoming code snippets (feel free to modify the logic if there are additional implementation requirements):

ASP.NET
<pre xmlns="http://ddue.schemas.microsoft.com/authoring/2003/5">
<telerik:RadGrid RenderMode="Lightweight" runat="server" AutoGenerateColumns="false" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource"
  Width="96%" AllowFilteringByColumn="True" AllowSorting="True" PageSize="15" AllowPaging="true"
  ShowStatusBar="true">
  <PagerStyle Mode="NextPrevAndNumeric" />
  <MasterTableView AutoGenerateColumns="false" AllowFilteringByColumn="True">
    <Columns>
      <telerik:GridBoundColumn DataField="ShipName" HeaderText="Ship name" SortExpression="ShipName"
        UniqueName="ShipName">
      </telerik:GridBoundColumn>
      <telerik:GridBoundColumn DataField="ShipAddress" HeaderText="Ship address" SortExpression="ShipAddress"
        UniqueName="ShipAddress">
      </telerik:GridBoundColumn>
      <telerik:GridBoundColumn DataField="OrderDate" HeaderText="Order date" SortExpression="OrderDate"
        UniqueName="OrderDate" DataFormatString="{0:dd/MM/yyyy}">
      </telerik:GridBoundColumn>
    </Columns>
  </MasterTableView></telerik:RadGrid> </pre>

With the .NET 3.5 build of RadGrid for ASP.NET AJAX and LINQ filter expressions enabled (EnableLinqExpressions = true), the filter expressions set for the grid either internally by its filtering mechanism or manually in code should conform to the LINQ expression syntax instead of the old T-SQL syntax. Only thus they will be evaluated properly by the control.

Not finding the help you need?
Contact Support