This is a migrated thread and some comments may be shown as answers.

Filter Textbox Issue

1 Answer 113 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Nelbin asked on 28 Nov 2013, 03:26 AM
Good Day Below is my RadGrid with a template column as date. The catch is that the date being bounded in the template is in long format. Therefore I convert it's value(as you can see on the DocDateLong). 

The problem is how can I handle the filter value. The input in the Filter textbox should be in date format and I will just convert it in integer. After the filter/rebind executes I will convert the integer back to it's date format input in the filter textbox.

<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="true"
                            AllowRowResize="False" AllowSorting="True" BorderStyle="None" GridLines="None"
                            PageSize="10" ShowFooter="False" ShowGroupPanel="false" Skin="WebBlue" Visible="False"
                            <ClientSettings AllowDragToGroup="true" EnablePostBackOnRowClick="true" EnableRowHoverStyle="true">
                                <Selecting AllowRowSelect="True" />
                                <ClientEvents OnRowSelected="RowSelected2" />
                            <MasterTableView AutoGenerateColumns="False" ClientDataKeyNames="Code" CommandItemDisplay="Top"
                                EnableHeaderContextMenu="True" Width="100%">
                                <%--          <CommandItemSettings ExportToPdfText="Export to PDF" />--%><CommandItemTemplate>
                                    <div align="left">
                                        <asp:Button ID="Button1" runat="server" CommandName="SaveSettings" Text="Save GridView Settings" /><asp:Button
                                            ID="Button2" runat="server" CommandName="DefaultSettings" Text="Restore Default Settings" /></div>
                                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
                                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
                                    <telerik:GridTemplateColumn AllowFiltering="False" CurrentFilterFunction="Custom"
                                        DataField="" DefaultInsertValue="" Groupable="true" HeaderText="" ReadOnly="True"
                                        SortExpression="" UniqueName="">
                                    <telerik:GridBoundColumn DataField="DecisionNo" DefaultInsertValue="" HeaderText="Decision No"
                                        SortExpression="DecisionNo" UniqueName="DecisionNo">
                                    <telerik:GridBoundColumn DataField="Subject" DefaultInsertValue="" HeaderText="Subject"
                                        SortExpression="Subject" UniqueName="Subject">
                                        <%--         <HeaderStyle Width="600" />--%></telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn DataField="DocDateLong" DefaultInsertValue="" FilterControlAltText="Filter date column"
                                        Groupable="false" HeaderText="Document Date" ReadOnly="True" SortExpression=""
                                            <asp:Label ID="lblDate" runat="server" Text='<%#Convert.ToDateTime("1900-01-01").AddDays(Convert.ToInt32(Eval("DocDateLong"))).ToString("MMMM dd, yyyy")%>'></asp:Label><%--                      <asp:Label ID="lblBday" runat="server" Text='<%# Eval("Birthdate","{0:MM/dd/yyyy}")%>'></asp:Label>--%></ItemTemplate>
                                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </MasterTableView><ClientSettings AllowColumnsReorder="True" AllowDragToGroup="True">
                                <Resizing AllowColumnResize="true" />
                            <PagerStyle Mode="NextPrevNumericAndAdvanced" />
                            <FilterMenu EnableImageSprites="False">

1 Answer, 1 is accepted

Sort by
Viktor Tachev
Telerik team
answered on 02 Dec 2013, 01:24 PM
Hi Nelbin,

The following article describes how filtering for a DateTime bound column could be done programmatically. This approach, however is not very intuitive as the user needs to enter the date manually in a TextBox control.
  • Filtering for DateTime bound column

If you do not want to handle the filtering manually you may consider using GridDateTimeColumn instead. This column renders RadDatePicker control to enter the date that will be used for filtering. Also range filtering is supported out of the box.

In order to modify the format the date is displayed, you could use the DataFormatString property. The following example shows definition for GridDateTimeColumn that displays the date in short format:

<telerik:GridDateTimeColumn DataField="Date" HeaderText="Date" UniqueName="Date" DataFormatString="{0:d}">

Note that the DataField needs to be of type DateTime in order for this to work properly. Custom DateTime format strings are also supported.

Viktor Tachev
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.
Asked by
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question