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

Requery Database upon filter

5 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 06 Mar 2009, 11:05 PM
So here is the situation:

I have a RadGrid with 4 columns and am allowing filtering. I'm using the <FilterTemplate> for all four columns and am binding using the NeedDataSource event.

Everything is working great except that for one of the fields I want to actually requery the database rather than just filter. It is a date field and I would rather limit the results from the database on this filter rather than just filter the existing data.

Sooo...here is what I tried:

    Public Sub RadComboboxEmployeeDateSubmittedFilter_SelectedIndexChanged(ByVal sender As ObjectByVal e As RadComboBoxSelectedIndexChangedEventArgs)  
 
        _startDate = String.Format(CultureInfo.CurrentCulture, "1/1/{0} 12:00:00 AM", e.Value)  
        _endDate  = String.Format(CultureInfo.CurrentCulture, "12/31/{0} 11:59:59 PM", e.Value)  
 
        Session.Item("TransactionLogYearFilter") = e.Value   
 
        RadGridEmployeeTransactions.Rebind()  
 
    End Sub 

RadComboboxEmployeeDateSubmittedFilter is the combobox that is inside the DateSubmitted column <FilterTemplate>, so the code above fires when the user selects an item from the combobox.

Here is my NeedDataSource handler:

    Private Sub RadGridEmployeeTransactions_NeedDataSource(ByVal source As ObjectByVal e As GridNeedDataSourceEventArgs) Handles RadGridEmployeeTransactions.NeedDataSource  
 
        Dim lTransactions As DataSet = Nothing 
 
        If UserType <> EnumHelper.UserType.Employee Then 
            Return 
        End If 
 
        Try 
 
            lTransactions = MiBenefitsHelper.GetEmployeeTransactions(GroupNumber, _  
                                                                     FamilyNumber, _  
                                                                     _startDate, _  
                                                                     _endDate)  
 
            RadGridEmployeeTransactions.DataSource = lTransactions  
 
        Catch ex As WcfException  
 
            PanelEmployeeTransactionLog.Visible = False 
            PanelUpdateStatus.Visible = True 
            LabelUpdateStatus.Text = "There was an error returning your transactions and they cannot be displayed at this time. EBMS has been notified of the problem and will have it resolved as soon as possible." 
            LabelUpdateStatus.ForeColor = Color.Red  
            ExceptionPolicy.HandleException(ex, "Global Policy")  
 
        End Try 
 
    End Sub 

As you can see it is referencing the _startDate and _endDate fields which get populated when the user makes a selection from the dropdown.

The problem is that RadGridEmployeeTransactions.Rebind() does not cause the RadGridEmployeeTransactions_NeedDataSource event to fire, which means the database is not re-queried and the results are not filtered.

How do I go about forcing the RadGridEmployeeTransactions_NeedDataSource event to fire so that it queries the database with the correct _startDate and _endDate values??

Thanks!

5 Answers, 1 is accepted

Sort by
0
jfkrueger
Top achievements
Rank 1
answered on 08 Mar 2009, 04:46 PM
Figured it out. Had to set the DataSource of the grid to Nothing before calling rebind to force the NeedsDataSource event to fire.

 Public Sub RadComboboxEmployeeDateSubmittedFilter_SelectedIndexChanged(ByVal sender As ObjectByVal e As RadComboBoxSelectedIndexChangedEventArgs)  
 
        _startDate = String.Format(CultureInfo.CurrentCulture, "1/1/{0} 12:00:00 AM", e.Value)  
        _endDate  = String.Format(CultureInfo.CurrentCulture, "12/31/{0} 11:59:59 PM", e.Value)  
 
        Session.Item("TransactionLogYearFilter") = e.Value   
 
        RadGridEmployeeTransactions.DataSource = Nothing
        RadGridEmployeeTransactions.Rebind()  
 
    End Sub 
0
Nicholas Walker
Top achievements
Rank 1
answered on 30 Jun 2009, 08:20 PM
I came across this same issue.  It seems like rebind() should actually rebind, not only rebind if it hasn't been already.  This should be logged as a bug...
0
Pavel
Telerik team
answered on 03 Jul 2009, 06:49 AM
Hi guys,

I have created a small sample in which the NeedDataSource event is executed as expected on Rebind. Try it and let me know what is different in your case.

Regards,
Pavel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Subhashini
Top achievements
Rank 1
answered on 26 Mar 2015, 06:37 PM
Awesome. You saved me from mentally breaking down :)
0
Subhashini
Top achievements
Rank 1
answered on 26 Mar 2015, 06:38 PM
Awesome :)
Tags
Grid
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
jfkrueger
Top achievements
Rank 1
Nicholas Walker
Top achievements
Rank 1
Pavel
Telerik team
Subhashini
Top achievements
Rank 1
Share this question
or