Modify Filter Value For ItemTemplate Column

3 posts, 0 answers
  1. Rodney
    Rodney avatar
    54 posts
    Member since:
    Mar 2015

    Posted 05 Apr 2017 Link to this post

    I have a GridTemplateColumn that is defined as with a DateType="System.DateTime", but actually contains a link button. The value in the column is a date, but since the ItemTemplate is defined as a link button the actual filter value is a string. When you search if you enter a valid date value it will filter correctly, but if you enter a 2, for example, the SQL gets an error because you obviously can't compare 2 to a date field.

    What I want to do is before the filter is performed validate that it is a valid date, if not just remove the filter. Additionally, I would really like to be able to add the date selector box next to the filter field. That would help in getting the date in the correct format.

    Below is the definition for the column:

    <telerik:GridTemplateColumn UniqueName="CREATEDON" DataField="CREATEDON" SortExpression="CREATEDON" HeaderText="Date Created" DataType="System.DateTime"
        CurrentFilterFunction="GreaterThanOrEqualTo" AutoPostBackOnFilter="true" HeaderStyle-Width="100">
        <ItemTemplate>
            <asp:LinkButton ID="lnkCreatedOn" runat="server" CommandName="VIEWTASK" CommandArgument='<%# Eval("TaskId") %>' OnClick="lnkCreatedOn_Click" />
        </ItemTemplate>
    </telerik:GridTemplateColumn>

     

    Thanks in advance.

    Rodney

     

  2. Eyup
    Admin
    Eyup avatar
    4030 posts

    Posted 10 Apr 2017 Link to this post

    Hi Rodney,

    There are 2 options to achieve this requirement:

    1. Use a FilterTemplate with a RadDatePicker:
    http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/filter-templates/defaultcs.aspx

    2. Replace the GridTemplateColumn with GridDateTimeColumn and add the LinkButtons manually during the ItemCreated event handler manually.

    I hope this will prove helpful.

    Regards,
    Eyup
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Rodney
    Rodney avatar
    54 posts
    Member since:
    Mar 2015

    Posted 10 Apr 2017 in reply to Eyup Link to this post

    Thank you so much, it worked perfectly.

    Rodney

Back to Top