ASP:GridView - making Pager always visible

by Sumant 30. July 2007 22:54

You would have noticed this while implementing ASP.net GridView control that if the record count in the grid is lesser than the grid's page size, then the pager doesn't appear.

There can be times when you want the pager to be visible all the time (like when you implement custom paging). In such a case there is no property available in the grid which can directly let you do so. But, there is a workaround to make this happen.

To make this happen, you will have to do following -

1. Handle the GridView's PreRender event.
2. In the PreRender event, fetch the GridView's 'BottomPagerRow'
3. Set BottomPagerRow's 'Visible' property to 'True'.

Example :

Visual Basic-Code: Making Pager Row Always Visible
Private Sub gvItems_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)Handles gvItems.PreRender 


Dim gv As System.Web.UI.WebControls.GridView = CType(sender, System.Web.UI.WebControls.GridView) 


    If Not gv Is Nothing Then 


        Dim PagerRow As GridViewRow = gv.BottomPagerRow 


        If Not PagerRow Is Nothing Then 


            PagerRow.Visible = True 


        End If 


    End If 


End Sub



Thats it!
Share   

Tags:

.NET | ASP.NET | Web Development

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

© 2008 Sumant Dubey

About this blog

Absolutely technical! The posts are about concepts, tricks, articles and links on technical subjects / problems which are not very obvious to understand / resolve. Purpose is to have this as the first-aid in the time of need.

RecentComments

Disclaimer

The opinions expressed on this website are my own personal opinions and do not represent my employer's view in anyway.