Filter does not work on GridBoundColumn(DateTime Type) if non-datetime text entered into column filter box.

2 posts, 1 answers
  1. Smruti Ranjan
    Smruti Ranjan avatar
    22 posts
    Member since:
    Feb 2012

    Posted 07 May 2012 Link to this post

    I am having a RadGrid on my page.

    This grid is having a GridBoundColumn of type "DateTime" with the CurrentFilterFunction="EqualTo" with in-place filter for the columns. My requirement is not to use the DatePicker icon to select date rather allow user to write text directly into filter through the column. But while trying with the filter functionality typing any non-datetime text into the column filter control and clicking enter postbacks the page but it does not filters, the same data remains there in the page, whereas it should filter and should show no data for any non-datetime entry into filter control.

    Here is my RadGridBound column's source:-

    <telerik:GridBoundColumn UniqueName="DOB" DataField="DOB" HeaderText="DOB"
                           CurrentFilterFunction="EqualTo" ShowFilterIcon="False" AutoPostBackOnFilter="True"
                           DataFormatString="{0:d}" DataType="System.DateTime">                       
                           <ItemStyle HorizontalAlign="Right" />
                           <HeaderStyle HorizontalAlign="Right" Width="100px" />
                           <FooterStyle HorizontalAlign="Right" />                       

    Can anybody have any idea for solving this issue.
    Thanks in advance.
  2. Answer
    Vasil avatar
    1604 posts

    Posted 10 May 2012 Link to this post

    Hi Smruti,

    When the text in DateInput is invalid, it server value is null. This is because the SelectedDate is of type DateTime? (nullable DateTime).
    In this case the filter will not be applied, because it is the same as empty.

    It is designed such way, because if we choose to filter with null value, then initially if you have CurrentFilterFunction set, and the same time the input is empty, no records will be displayed. Which would be still wrong.

    As a workaround you can use custom filtering. Place a DateInput in the filter template. And on PostBack do filter, even if it is in invalid stage.

    the Telerik team
    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 their blog feed now.
Back to Top