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

Filtering between dates

4 Answers 100 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ahmed Ilyas
Top achievements
Rank 1
Ahmed Ilyas asked on 03 Apr 2012, 05:40 PM
Hi.
Following some examples, I found this:

http://www.telerik.com/community/code-library/aspnet-ajax/general/filtering-range-with-raddatepicker-instances-in-a-custom-filtering-column.aspx

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>
                          
                        <FilterTemplate>
                            <telerik:RadComboBox ID="ddlDateFilter" runat="server" DropDownWidth="200px">   
                                <Items>
                                    <telerik:RadComboBoxItem Text="" Selected="true" />
                                </Items>
                                <ItemTemplate>
                                  
                                    From <telerik:RadDatePicker ID="RadDatePickerFrom" runat="server" onclick="PreventDropDownClose(event);">
                                    </telerik:RadDatePicker>
                                    To <telerik:RadDatePicker ID="RadDatePickerTo" runat="server" onclick="PreventDropDownClose(event);">
                                    </telerik:RadDatePicker>                                    
                                    <asp:Button ID="cmdFilterDates" runat="server" Text="Filter" CommandName="FilterDates" />
                                </ItemTemplate>
                            </telerik:RadComboBox>
                        </FilterTemplate>
                          
                    </telerik:GridTemplateColumn>


Code:

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.

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Apr 2012, 06:39 AM
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.
aspx:
<asp:Button ID="cmdFilterDates" runat="server" Text="Filter" CommandName="FilterDates"  OnClick="cmdFilterDates_Click" />

C#:
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();
}

Thanks,
Shinu.
0
Ahmed Ilyas
Top achievements
Rank 1
answered on 04 Apr 2012, 09:34 AM
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"
0
Ahmed Ilyas
Top achievements
Rank 1
answered on 04 Apr 2012, 09:49 AM
I had tried what you suggested and STILL get null (Nothing in VB.NET) For the SelectedDate
0
Pavlina
Telerik team
answered on 05 Apr 2012, 09:58 PM
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.

Greetings,
Pavlina
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.
Tags
General Discussions
Asked by
Ahmed Ilyas
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ahmed Ilyas
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or