Gridview BottomPagerRow not finding

2.4k Views Asked by At

I placed a ASP DataRepeater in the PagerTemplate of a GridView. I need to find the DataRepeater in my code

I'm Trying this.

Repeater rptPager = (Repeater)gv_Inbox.BottomPagerRow.FindControl("rptPager");

But this is Throwing a Exception

Object reference not set to an instance of an object.

When I try

GridViewRow row = gv_Inbox.BottomPagerRow;

It returns Null.

I'm trying Custom paging in GridView. In that I'm able to place the Repeater Below the GridView and use paging. But I want to place the repeater on the bottom of the GridView ie. the Pager Row. So how can I do this??

Can you Help Me??

3

There are 3 best solutions below

3
On BEST ANSWER

The BottomPagerRow property is available only after the GridView control creates the bottom pager row in the RowCreated event.

try event like DataBound, you can find the controls inside BottomPagerRow

0
On

Add following line to "RowDataBound" then you will have access.

If e.Row.RowType <> DataControlRowType.Pager Then Exit Sub
0
On

I found that if the method returning the count of records for the GridView (using ObjectDataSource) returned more records that the method returning the actual records then, the following would throw an error related to BottomPagerRow.

Private Sub gv_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles gv.PreRender
    If gv.PageCount = 1 Then gv.BottomPagerRow.Visible = False
End Sub

I fixed the methods to both return the same number of results and all was well.