Force data refresh when using NeedDataSource

4 posts, 0 answers
  1. Tayonee
    Tayonee avatar
    52 posts
    Member since:
    Nov 2006

    Posted 25 Mar 2015 Link to this post

    This seems like it should be an easy thing to figure out, but I haven't found a solution to my problem. I wire up a PivotGrid to a DataTable (which I store in Session State between calls) using the NeedDataSource event handler. I have a search form on my page with 7 different parameters for the stored procedure that I call within that method.

    What I am finding is that the search button works the first time (on page load), but clicking the search button doesn't cause the data to be recalled again. I would think that the rebinding of the pivot grid would be straighforward, and would cause the NeedDataSource event to fire again. Because of the size of the dataset (potentially 45,000 records) I need to store it in session between calls.

    What am I missing here? 

    The search button only calls:

    pvtCMStoG2.DataBind()

    The NeedDataSource event looks like this:
     
    Private Sub pvtCMStoG2_NeedDataSource(sender As Object, e As PivotGridNeedDataSourceEventArgs) Handles pvtCMStoG2.NeedDataSource
        'Get an assign the data source.
        pvtCMStoG2.DataSource = GetPivotGridData()
    End Sub
     
     
    Public Function GetPivotGridData() As DataTable
        'Decalre local variables.
        Dim myDataTable As New DataTable()
     
     
        'Check to see if there is anything in Session for this.
        If Session("ReconciliationTime") IsNot Nothing Then
            'Retrieve from session.
            myDataTable = CType(Session("ReconciliationTime"), DataTable)
        Else
            'Set up the connection.
            Dim m_strConnectionString As [String] = ConfigurationManager.ConnectionStrings("SOREOConnection").ConnectionString
            Dim m_objConnection As New SqlConnection(m_strConnectionString)
     
            Dim m_objSQLCommand As New SqlCommand
            Dim m_cmdParameter As SqlParameter
     
            'Set the command properties.
            With m_objSQLCommand
                .Connection = m_objConnection
     
                'Set the command timeout value to wait indefinitely.
                .CommandTimeout = 0
     
                'Set the core properties.
                .CommandText = "[reconciliation].[cspCMStoG2TimesheetValidation]"
                .CommandType = CommandType.StoredProcedure
            End With
     
     
            'Create and set the parameter values.
            m_cmdParameter = New SqlParameter 'With {.ParameterName = "BeginDate", .SqlDbType = SqlDbType.DateTime}
            With m_cmdParameter
                .ParameterName = "@BeginDate"
                .SqlDbType = SqlDbType.DateTime
     
                'Set the value.
                .Value = ctlBillingPeriodPicker.StartDate
            End With
     
            'Add the parameter to the commands.
            m_objSQLCommand.Parameters.Add(m_cmdParameter)
     
     
            'Create and set the parameter values.
            m_cmdParameter = New SqlParameter
            With m_cmdParameter
                .ParameterName = "@EndDate"
                .SqlDbType = SqlDbType.DateTime
     
                'Set the value.
                .Value = ctlBillingPeriodPicker.EndDate
            End With
     
            'Add the parameter to the commands.
            m_objSQLCommand.Parameters.Add(m_cmdParameter)
     
     
            'Create and set the parameter values.
            m_cmdParameter = New SqlParameter
            With m_cmdParameter
                .ParameterName = "@EmployeeID"
                .SqlDbType = SqlDbType.UniqueIdentifier
     
                'Set the value.
                If String.IsNullOrEmpty(ctlEmployeePicker.SelectedEmployeeID) Then
                    .Value = System.DBNull.Value
                Else
                    .Value = ctlEmployeePicker.SelectedEmployeeID
                End If
            End With
     
            'Add the parameter to the commands.
            m_objSQLCommand.Parameters.Add(m_cmdParameter)
     
     
            'Create and set the parameter values.
            m_cmdParameter = New SqlParameter
            With m_cmdParameter
                .ParameterName = "@CustomerID"
                .SqlDbType = SqlDbType.UniqueIdentifier
     
                'Set the value.
                If String.IsNullOrEmpty(ctlCustomerPicker.SelectedCustomerID) Then
                    .Value = System.DBNull.Value
                Else
                    .Value = ctlCustomerPicker.SelectedCustomerID
                End If
            End With
     
            'Add the parameter to the commands.
            m_objSQLCommand.Parameters.Add(m_cmdParameter)
     
     
            'Create and set the parameter values.
            m_cmdParameter = New SqlParameter
            With m_cmdParameter
                .ParameterName = "@FundingAgency"
                .SqlDbType = SqlDbType.VarChar
     
                'Set the value.
                If String.IsNullOrEmpty(ctlFundingOrganization.SelectedFundingOrganizationName) Then
                    .Value = System.DBNull.Value
                Else
                    .Value = ctlFundingOrganization.SelectedFundingOrganizationName
                End If
            End With
     
            'Add the parameter to the commands.
            m_objSQLCommand.Parameters.Add(m_cmdParameter)
     
     
            'Create and set the parameter values.
            m_cmdParameter = New SqlParameter
            With m_cmdParameter
                .ParameterName = "@TimesheetID"
                .SqlDbType = SqlDbType.Int
     
                'Assign the value
                If chkSingleTimesheetID.Checked = True Then
                    .Value = radTimesheetID.Value
                Else
                    .Value = System.DBNull.Value
                End If
            End With
     
            'Add the parameter to the commands.
            m_objSQLCommand.Parameters.Add(m_cmdParameter)
     
            
            'Create and set the parameter values.
            m_cmdParameter = New SqlParameter
            With m_cmdParameter
                .ParameterName = "@IncludeLastImport"
                .SqlDbType = SqlDbType.Bit
     
                'Assign the value
                .Value = chkIncludeLastImport.Checked
            End With
     
            'Add the parameter to the commands.
            m_objSQLCommand.Parameters.Add(m_cmdParameter)
     
     
            'Create and set the parameter values.
            m_cmdParameter = New SqlParameter
            With m_cmdParameter
                .ParameterName = "@ErrorsOnly"
                .SqlDbType = SqlDbType.Bit
     
                'Assign the value
                .Value = chkErrorsOnly.Checked
            End With
     
            'Add the parameter to the commands.
            m_objSQLCommand.Parameters.Add(m_cmdParameter)
     
     
     
            'Set up the DataAdapter
            Dim DataAdapter As SqlDataAdapter = New SqlDataAdapter
            DataAdapter.SelectCommand = m_objSQLCommand
     
     
            Try
                'Open the connection.
                m_objConnection.Open()
     
                'Fill the data adapter.
                DataAdapter.Fill(myDataTable)
            Finally
                'Close the connection.
                m_objConnection.Close()
            End Try
     
     
            'Add it to the session.
            Session("ReconciliationTime") = myDataTable
        End If
     
     
        'Return the final dataset.
        Return myDataTable
    End Function
  2. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 30 Mar 2015 Link to this post

    Hello,

    Note that DataBind() is a method that is used for simple data binding. However, advanced and simple data binding must not be mixed. This could produce unexpected results.

    If you need to rebind the grid explicitly you should use Rebind(). Try to modify the code and see how the behavior changes.

    pvtCMStoG2.Rebind()


    Regards,
    Viktor Tachev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tayonee
    Tayonee avatar
    52 posts
    Member since:
    Nov 2006

    Posted 31 Mar 2015 in reply to Viktor Tachev Link to this post

    Thanks Victor! I will give that a shot - I hadn't realize the subtle differences between the two methods since I normally don't use this advanced data binding logic... my datasets are not normally anywhere near this large!

    Thanks,
    Mike
  5. Viktor Tachev
    Admin
    Viktor Tachev avatar
    1488 posts

    Posted 01 Apr 2015 Link to this post

    Hi Mike,

    Please give the approach a try and let us know how it works.

    Regards,
    Viktor Tachev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top