Filtering between dates

5 posts, 0 answers
  1. Ahmed Ilyas
    Ahmed Ilyas avatar
    51 posts
    Member since:
    Feb 2010

    Posted 03 Apr 2012 Link to this post

    Following some examples, I found this:

    I am trying to filter a data source between 2 selected dates.

    I am almost there with the implementation of the solution however the problem is, even when the dates are selected, the SelectedDate on the ItemCommand event is null (Nothing in VB.NET)

    any ideas where I have gone wrong?

    <telerik:GridTemplateColumn HeaderStyle-HorizontalAlign="Center" 
                            HeaderText="DateFilter" SortExpression="DateTime" UniqueName="DateFilter" 
                            AllowFiltering="true" ShowFilterIcon="true" AutoPostBackOnFilter="false" DataType="System.DateTime" 
                            DataField="DateTime" ItemStyle-HorizontalAlign="Left">
                            <HeaderStyle Width="90px"></HeaderStyle>
                            <ItemStyle HorizontalAlign="Left" Width="90px"></ItemStyle>
                                <telerik:RadComboBox ID="ddlDateFilter" runat="server" DropDownWidth="200px">   
                                        <telerik:RadComboBoxItem Text="" Selected="true" />
                                        From <telerik:RadDatePicker ID="RadDatePickerFrom" runat="server" onclick="PreventDropDownClose(event);">
                                        To <telerik:RadDatePicker ID="RadDatePickerTo" runat="server" onclick="PreventDropDownClose(event);">
                                        <asp:Button ID="cmdFilterDates" runat="server" Text="Filter" CommandName="FilterDates" />


    Protected Sub grdShiftObservation_OnItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdShiftObservation.ItemCommand
            If String.Equals(e.CommandName, "filterdates", StringComparison.OrdinalIgnoreCase) Then
                Dim cell As TableCell = CType(e.Item, Telerik.Web.UI.GridFilteringItem)("DateFilter")
                Dim dateFilterComboBox As RadComboBox = CType(cell.Controls(0).FindControl("ddlDateFilter"), RadComboBox)
                Dim dateFrom As RadDatePicker = CType(dateFilterComboBox.SelectedItem.FindControl("RadDatePickerFrom"), RadDatePicker)
                Dim dateTo As RadDatePicker = CType(dateFilterComboBox.SelectedItem.FindControl("RadDatePickerTo"), RadDatePicker)
            End If
        End Sub

    dateFrom and dateTo show "Nothing"

    any ideas? I want to be able to obtain the dates the user has selected.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 04 Apr 2012 Link to this post

    Hello Ahmed,

    You can attach an onclick event to Button inside the FilterTemplate and access the controls using NamingContainer property. Here is the sample code.
    <asp:Button ID="cmdFilterDates" runat="server" Text="Filter" CommandName="FilterDates"  OnClick="cmdFilterDates_Click" />

    protected void cmdFilterDates_Click(object sender, EventArgs e)
      Button btn = (Button)sender;
      RadComboBoxItem item = (RadComboBoxItem)btn.NamingContainer;
      RadDatePicker pkr1 = (RadDatePicker)item.FindControl("RadDatePickerFrom");
      RadDatePicker pkr2 = (RadDatePicker)item.FindControl("RadDatePickerTo");
      string value1 = pkr1.SelectedDate.ToString();
      string value2 = pkr2.SelectedDate.ToString();

  3. Ahmed Ilyas
    Ahmed Ilyas avatar
    51 posts
    Member since:
    Feb 2010

    Posted 04 Apr 2012 Link to this post

    Thanks. I will try this.

    out of curiosity, how do I do the filtering on the client side when the user selects the dates and presses the filter button?

    for example, the current solution (which im trying to follow as its not my project) - when a user filters an existing simple date column, it filters and no code on server side references filtering the dataset/data source but it "works"
  4. Ahmed Ilyas
    Ahmed Ilyas avatar
    51 posts
    Member since:
    Feb 2010

    Posted 04 Apr 2012 Link to this post

    I had tried what you suggested and STILL get null (Nothing in VB.NET) For the SelectedDate
  5. Pavlina
    Pavlina avatar
    6187 posts

    Posted 05 Apr 2012 Link to this post

    Hi Ahmed,

    I checked your account and it occurs that you have opened several forum threads for the same thing. It is highly recommended that you keep related questions in one support thread or a forum post, so that we can easily keep track of your support history and provide better answers in a shorter time.

    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