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 DataPager
s 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,
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