0

I have a ListView with three DataPager associated to it, all inside an UpdatePanel.

The first DataPager is only to show the link to the previous page:

<asp:DataPager ID="dpPrev" runat="server" PagedControlID="lvExperiences" QueryStringField="page" PageSize="4">
  <Fields>
    <asp:NextPreviousPagerField ShowNextPageButton="false" ButtonCssClass="PagePrev" />
  </Fields>
</asp:DataPager>

The second one is for the regular sequency of pages:

<asp:DataPager ID="dpList" runat="server" PagedControlID="lvExperiences" QueryStringField="page" PageSize="4">
  <Fields>
    <asp:NumericPagerField ButtonType="Link" CurrentPageLabelCssClass="PageCurrent" />
  </Fields>
</asp:DataPager>

And the last one is for the link to the next page:

<asp:DataPager ID="dpNext" runat="server" PagedControlID="lvExperiences" QueryStringField="page" PageSize="4">
  <Fields>
    <asp:NextPreviousPagerField ShowPrevPageButton="false" ButtonCssClass="PagePrev" />
  </Fields>
</asp:DataPager>

I put that controls separately, so I can disable the prev/next link in code behind depending if we are in the first/last page :

Protected Sub lvExperiences_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvExperiences.DataBound
    Dim page As Integer = 1
    If Not Request("page") Is Nothing Then
        page = Integer.Parse(Request("page"))
    End If
    dpPrev.Visible = ((dpPrev.PageSize * page) > dpPrev.TotalRowCount And (page > 1))
    dpNext.Visible = ((dpNext.PageSize * page) < dpNext.TotalRowCount)
End Sub

It works perfectly, but, such the DataPager is changing the URL in order to add the ?page=X, it makes a full PostBack. If I remove the DataBound method and the QueryStringField attributes from the DataPagers the UpdatePanel do its job and refresh only the ListView.

Anybody knows a way to know the current page without using the QueryStringField attribute?

Thanks a lot of,

1 Answer 1

1

Try this:

Protected Sub lvExperiences_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvExperiences.DataBound
   dpPrev.Visible = dpPrev.StartRowIndex > 0
   dpNext.Visible = (dpNext.StartRowIndex + dpNext.PageSize) < dpNext.TotalRowCount
End Sub
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.