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

Custom Filter - RadDatePicker to Handle DBNULL Values

2 Answers 118 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Deva Kumar
Top achievements
Rank 1
Deva Kumar asked on 19 Nov 2009, 10:38 AM
Dear Experts,

I have a issue with performing custom filtering using RadDatePicker on RadGrid.

I have a datetime column on the grid and I am using template column to assign the values on the grid.

The RadDatePicker control works perfect on one date column which contains DateTimeValues values on all the rows.

But it is not working on a column where there are very few values and also contains DBNULL values. Thanks in advance.

Here is the code
-------------------------------------

<FilterTemplate>
                                            <telerik:RadDatePicker ID="PickupDatePicker" runat="server" Width="90px" ClientEvents-OnDateSelected="PickupDateSelected"
                                                DbSelectedDate='<%# SetPickupDate(Container) %>' />
                                            <telerik:RadScriptBlock ID="RadScriptPickupDate" runat="server">

                                                <script type="text/javascript">
                                                    function PickupDateSelected(sender, args) {
                                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                        var date = FormatPickupSelectedDate(sender);                                                       
                                                        tableView.filter("Pickup_Dt", date, "EqualTo");
                                                    }
                                                    function FormatPickupSelectedDate(picker) {
                                                        var date = picker.get_selectedDate();
                                                        var dateInput = picker.get_dateInput();
                                                        var formattedDate = dateInput.get_dateFormatInfo().FormatDate(date, dateInput.get_displayDateFormat());
                                                        return formattedDate;
                                                    }
                                                </script>

                                            </telerik:RadScriptBlock>
                                        </FilterTemplate>
-------------------------------------
protected DateTime? SetPickupDate(Telerik.Web.UI.GridItem item)
    {
        if (item.OwnerTableView.GetColumn("Pickup_Dt").CurrentFilterValue == string.Empty)
        {
            return new DateTime?();
        }
        else
        {
            return DateTime.Parse(item.OwnerTableView.GetColumn("Pickup_Dt").CurrentFilterValue);
        }
    }   

 protected void uxRGrid_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridFilteringItem)
            {
             Telerik.Web.UI.RadDatePicker dtpickerPickupDate = (Telerik.Web.UI.RadDatePicker)(e.Item as Telerik.Web.UI.GridFilteringItem)["Pickup_Dt"].Controls[1];
                dtpickerPickupDate.Culture = Thread.CurrentThread.CurrentUICulture; 
            }
}
-------------------------------------

2 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 24 Nov 2009, 04:42 PM
Hi Deva,

Can you check whether you use the .NET 3.5 build of RadControls (2009.3.1103.35) in your projec and set EnableLinqExpressions = false through your RadGrid's tag? If not, try it out to see whether this helps.
 
Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Deva Kumar
Top achievements
Rank 1
answered on 24 Nov 2009, 04:59 PM
Thanks a lot for your kind help Sebastian.

Sorry, I am not using the latest version which you have provided. (Mine is 2009.2.826.35). I should request my client manager to get the update.

I have tried and implemented the other way - which I shouldn't have done. I assigned DateTime.MinValue to all the DateTime columns which was having DBNULL values. By this I was able to surpass the problem temporarily. And while displaying on the screen, I will avoid displaying the DateTime.MinValue.

Thank you Sebastian. I will get the latest update and try with your solution.

Thank you,
Deva
Tags
Calendar
Asked by
Deva Kumar
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Deva Kumar
Top achievements
Rank 1
Share this question
or