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

RadDateTimePicker in a RadGrid

2 Answers 93 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Smiely
Top achievements
Rank 1
Smiely asked on 20 Dec 2010, 11:46 PM
I have a date column and have a From dateTime To dateTime filter on that. I got that working but now it doesn't work with another column filters. If I select another filter for a specific dateTime rage, the dateTime selection is gone and dates are displayed as per the another filter.
Please help...

<FilterTemplate>
                        From
 <telerik:RadDateTimePicker ID="FromOrderDatePicker" runat="server" Width="185px"
 MinDate="01-01-2010" MaxDate="12-31-2010" FocusedDate="12-15-2010" DbSelectedDate='<%# startDate1 %>'>
<TimeView ID="TimeView1" OnClientTimeSelected="DateSelected" runat="server">
 </TimeView>
 </telerik:RadDateTimePicker>
                        to
 <telerik:RadDateTimePicker ID="ToOrderDatePicker" runat="server" Width="185px" MinDate="01-01-2010"
MaxDate="12-31-2010" FocusedDate="12-15-2010" DbSelectedDate='<%# endDate1 %>'>
 <TimeView ID="TimeView2" OnClientTimeSelected="DateSelected" runat="server">
 </TimeView>
 </telerik:RadDateTimePicker>
 <telerik:RadScriptBlock ID="RadScriptBlock111" runat="server">
  
  <script type="text/javascript">
 function DateSelected(sender, args) {
     var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
     tableView.filter("DateCreated", "", "Between");
                                }
                                  
   </script> </telerik:RadScriptBlock>
  </FilterTemplate>

And Code behind is...

protected void taskGrid_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.FilterCommandName)
            {
                Pair filterPair = (Pair)e.CommandArgument;
  
                switch (filterPair.Second.ToString())
                {
          case "DateCreated":
e.Canceled = true;
this.startDate1 = ((e.Item as GridFilteringItem)[filterPair.Second.ToString()].FindControl("FromOrderDatePicker") as RadDateTimePicker).SelectedDate;
                          
this.endDate1 = ((e.Item as GridFilteringItem)[filterPair.Second.ToString()].FindControl("ToOrderDatePicker") as RadDateTimePicker).SelectedDate;
                          
taskGrid.MasterTableView.FilterExpression = "('" + startDate1.Value.ToString("MM/dd/yyyy HH:mm:ss") + "' <= [DateCreated] AND [DateCreated] <= '" + endDate1.Value.ToString("MM/dd/yyyy HH:mm:ss") + "')";
taskGrid.MasterTableView.Rebind();
                break;
                    default:
                        break;
                }
            }

2 Answers, 1 is accepted

Sort by
0
Smiely
Top achievements
Rank 1
answered on 21 Dec 2010, 10:00 PM
I got one baby step working. If I select dateTime last the following code is working. Can not figure out logic if I pick DateTime range first and then other filters.

if (e.CommandName == RadGrid.FilterCommandName)
{
    Pair filterPair = (Pair)e.CommandArgument;
    if (filterPair.Second.ToString() == "DateCreated")
     {
         e.Canceled = true;
         this.startDate1 = ((e.Item as GridFilteringItem)[filterPair.Second.ToString()].FindControl("FromDatePicker") as RadDateTimePicker).SelectedDate;
  
         this.endDate1 = ((e.Item as GridFilteringItem)[filterPair.Second.ToString()].FindControl("ToDatePicker") as RadDateTimePicker).SelectedDate;
    if (taskGrid.MasterTableView.FilterExpression == "")
    {
      taskGrid.MasterTableView.FilterExpression = "('" + startDate1.Value.ToString("MM/dd/yyyy HH:mm:ss") + "' <= [DateCreated] AND [DateCreated] <= '" + endDate1.Value.ToString("MM/dd/yyyy HH:mm:ss") + "')";
      }
      else
      {
       taskGrid.MasterTableView.FilterExpression += " AND ('" + startDate1.Value.ToString("MM/dd/yyyy HH:mm:ss") + "' <= [DateCreated] AND [DateCreated] <= '" + endDate1.Value.ToString("MM/dd/yyyy HH:mm:ss") + "'  )";
         }  
 }
   taskGrid.Rebind();
Please help.................
0
Tsvetina
Telerik team
answered on 22 Dec 2010, 03:45 PM
Hello Smiely,

This is probably happening because you are not adding this filter expression to the new filter expression built by RadGrid.

Please look at the Example2: Replacing the filter expression section of this help article in order to see how you should proceed in a situation where you replace the default grid filter.

Greetings,
Tsvetina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Calendar
Asked by
Smiely
Top achievements
Rank 1
Answers by
Smiely
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or