4

I have a standard ASP.Net DataPager with a standard ListView (using a DataTable as a data source).

When I set PageSize="24" in the design code:

<asp:DataPager runat="server" ID="DataPager1" PagedControlID="ListView1" QueryStringField="page" PageSize="24" >

the paging works as advertised.

However, when I then change that in code, in the Page_Load, eg:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    DataPager1.PageSize = 48
End Sub

the paging ceases to work completely, while the initial loaded data set is indeed 48 items.

I can't see anything in the code which would affect this, so I'm wondering if I'm missing something - should I be changing something else?

Regards

Moo

2 Answers2

10
Protected Sub DataPager1_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataPager1.Init
    DataPager1.PageSize = 48
End Sub

I managed to get this working by setting the page size property in the init event for the datapager.

Michael
  • 11,571
  • 4
  • 63
  • 61
1

This sort of error I usually find is a data-binding issue... either binding when you shouldn't, or not re-binding when appropriate. Hard to tell from your little snippet of code.

I am unfamiliar with the DataPager object, but I suspect it must rebind the data when you set the PageSize. If so, then every time the page loads it is re-binding and you are losing events. Have you tried this?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack
        DataPager1.PageSize = 48
    End If
End Sub
Bryan
  • 8,748
  • 7
  • 41
  • 62