Wednesday, 14 October 2009

Hide your datapager when there's only one page

It seems really strange to me that this isn't a configurable property of a datapager. If your datapager is in the LayoutTemplate of your Listview then this code will hide it for you:

Protected Sub ListView1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
Dim pager As DataPager = DirectCast(ListView1.FindControl("DataPager1"), DataPager)
If pager.PageSize < pager.TotalRowCount Then
pager.Visible = True
pager.Visible = False
End If
End Sub

Just place this as an OnPreRender handler for the list.

No comments:

Post a Comment

Comments are moderated, so you'll have to wait a little bit before they appear!