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

Problem with template filter for datetime column

0 Answers 188 Views
Grid
This is a migrated thread and some comments may be shown as answers.
john
Top achievements
Rank 1
john asked on 20 Jul 2011, 09:00 AM
Hi,

I'm testing RadGrid filters and I have problems with template filters.

I want to have a template filter for a column binded to a datetime datafield, for filtering between two dates. The template has these controls:
    - a Date picker for start date.
    - a Date picker for end date.
    - a button to apply/clear the filter.

These are pieces of the code I'm using:

- ASPX:
...
    <telerik:GridBoundColumn DataField="DateTimeFieldDB"
        DataType="System.DateTime"
        FilterControlAltText="Filter DateTimeFieldDB column"
        HeaderText="Date/Time" SortExpression="DateTimeFieldDB"
        UniqueName="DateTimeCol" HeaderButtonType="LinkButton">
        <HeaderStyle Width="150px" />
                    <FilterTemplate>
                        <telerik:RadDatePicker ID="FromDT" runat="server" Width="70px"/>
                        <telerik:RadDatePicker ID="ToDT" runat="server" Width="70px"/>
                        <telerik:RadButton ID="btnFilterDT" runat="server" Text="Filter" CommandName="cmdFilterDT">
                        </telerik:RadButton>
                    </FilterTemplate>
    </telerik:GridBoundColumn>
...


- CS:
protected void myGrid_ItemCommand(object sender, GridCommandEventArgs e)
 {
     switch (e.CommandName)
     {
         case "cmdFilterDT":
             GridColumn column = myGrid.MasterTableView.GetColumnSafe("DateTimeCol");
 
             GridItem[] fItems = myGrid.MasterTableView.GetItems(GridItemType.FilteringItem);
             RadDatePicker dpFrom = (RadDatePicker)fItems[0].FindControl("FromDT");
             RadDatePicker dpTo = (RadDatePicker)fItems[0].FindControl("ToDT");
             string sDateFrom = string.Format("{0: dd/MM/yyyy}", dpFrom.SelectedDate);
             string sDateTo = string.Format("{0: dd/MM/yyyy}", dpTo.SelectedDate);
 
             if (dpFrom.SelectedDate.ToString() != string.Empty && dpTo.SelectedDate.ToString() != string.Empty)
             {
                 column.CurrentFilterFunction = GridKnownFunction.Between;
                 column.CurrentFilterValue = string.Format("{0} {1}", sDateFrom, sDateTo);
             }
             else
             {
                 column.CurrentFilterFunction = GridKnownFunction.NoFilter;
                 column.CurrentFilterValue = "";
             }
 
             myGrid.MasterTableView.Rebind();
             break;
     }
 }


When I click the filter button the command is fired and the code for 'cmdFilterDT' is executed, but no changes are displayed in the grid (I have a rule from myGrid to myGrid in an RadAjaxManager for refreshing the changes).

Anyone can help me? I've been reading the help and the grid forum but I don't find any solution to this method for using template filters.

Thanks in advance,
John.



No answers yet. Maybe you can help?

Tags
Grid
Asked by
john
Top achievements
Rank 1
Share this question
or