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

PageSize property not updating during postback

5 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan Lehmann
Top achievements
Rank 1
Dan Lehmann asked on 13 Oct 2011, 04:35 PM
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

5 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 14 Oct 2011, 07:02 AM
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
0
Dan Lehmann
Top achievements
Rank 1
answered on 17 Oct 2011, 05:10 PM
I'm still troubleshooting, recreating a new project in an attempt to reproduce the problem. I'll report back.

Thanks,
Dan
0
Dan Lehmann
Top achievements
Rank 1
answered on 17 Oct 2011, 09:49 PM
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
0
Accepted
Tsvetoslav
Telerik team
answered on 18 Oct 2011, 08:58 AM
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
0
Dan Lehmann
Top achievements
Rank 1
answered on 18 Oct 2011, 03:04 PM
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!
Tags
Grid
Asked by
Dan Lehmann
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Dan Lehmann
Top achievements
Rank 1
Share this question
or