PageSize property not updating during postback

6 posts, 1 answers
  1. Dan Lehmann
    Dan Lehmann avatar
    103 posts
    Member since:
    May 2011

    Posted 13 Oct 2011 Link to this post

    I am binding with objects and paging my data, relying on PageSize and PageIndex properties of the RadGrid to determine what rows to pull. When I change the page size I step into RadGrid1_PageSizeChanged and verify that e.NewPageSize is correct. I then step into RadGrid1_NeedDataSource and the PageSize is still set to the old value. I was thinking of using Session or ViewState variables to store the values as a work around but shouldn't the PageSize be set to the new page size right after the PageSizeChanged event?

    Here is my VB:

    Protected Sub RadGrid1_PageSizeChanged(sender As Object, e As Telerik.Web.UI.GridPageSizeChangedEventArgs) Handles RadGrid1.PageSizeChanged
        RadGrid1.CurrentPageIndex = 0
        Session("LeadsPageSize") = e.NewPageSize
        RadGrid1.Rebind()
    End Sub
    Protected Sub RadGrid1_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        Dim Customer_id As String = DirectCast(Me.Parent.FindControl("hfCustomer_id"), HiddenField).Value
        If Customer_id = "" OrElse Not IsNumeric(Customer_id) Then
            divLeads.Visible = False
        Else
            Dim StartRow As Int32
            Dim EndRow As Int32
      
            StartRow = RadGrid1.CurrentPageIndex * RadGrid1.PageSize + 1
            EndRow = StartRow + RadGrid1.PageSize - 1
            If EndRow > RadGrid1.VirtualItemCount Then EndRow = RadGrid1.VirtualItemCount
            If StartRow > EndRow Then StartRow = EndRow
      
            Dim objDT As DataTable = Customer.SelectLeadsRangeByCustomer(Customer_id, StartRow, EndRow)
            If objDT.Rows.Count = 0 Then
                divLeads.Visible = False
            Else
                RadGrid1.DataSource = objDT
            End If
        End If
    End Sub

    What am I doing wrong?

    Thanks,
    Dan
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 14 Oct 2011 Link to this post

    Hi Dan,

    I tried to reproduce the problem in question but to no succes - please, take a look at the attached sample and give us more details on how to reproduce the issue.

    Regards, Tsvetoslav
    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dan Lehmann
    Dan Lehmann avatar
    103 posts
    Member since:
    May 2011

    Posted 17 Oct 2011 Link to this post

    I'm still troubleshooting, recreating a new project in an attempt to reproduce the problem. I'll report back.

    Thanks,
    Dan
  5. Dan Lehmann
    Dan Lehmann avatar
    103 posts
    Member since:
    May 2011

    Posted 17 Oct 2011 Link to this post

    I was able to fix the problem. I was calling RadGrid.DataBind() in a case where I should have called RadGrid.Rebind() so the grid was stuck with old data. I'm now calling .DataBind only during postbacks that involve the grid directly. I've got about 10 other controls on the page that can change the grid data and am now calling .Rebind() for those. Everything is working.

    Thanks,
    Dan
  6. Answer
    Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 18 Oct 2011 Link to this post

    Hi Dan,

    Do note the differenc between Advanced data-binding and Simple data-binding. When using advanced data-binding you should not be calling the DataBind() method of the grid anywhere. In case you need to repopulate the grid with new data, you should call Rebind() as you have correctly found out. Hope this additional information will provide futher insight.

    Regards, Tsvetoslav
    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
  7. Dan Lehmann
    Dan Lehmann avatar
    103 posts
    Member since:
    May 2011

    Posted 18 Oct 2011 Link to this post

    Yes that did help. I'm using Advanced binding and there were 2 places I was still using DataBind(), in my PageIndexChanged and PageSizeChanged handlers. Both were unnecessary because I just learned, after paging events is one of the times NeedDataSource fires automatically.

    Thanks!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017