Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net GridView Pager disappears!

I have a datagridview that is using paging, it works perfectly fine and I have a drop down that allows the user to change the 'PageSize' property - 10, 15, 25, 50, 100, 1000 etc.

When I select a value for the PageSize that is greater than the row count for the grid the Pager is disappearing from both the top & bottom of the grid.

Anyone got any ideas why?

I'm using a custom PageTemplate element in the aspx page.

Cheers

Ollie

like image 633
AwkwardCoder Avatar asked Jun 30 '09 10:06

AwkwardCoder


2 Answers

Behaviour is by design. You can force it to remain visible by setting the Visible property of the pager row (accessed using either TopPagerRow or BottomPagerRow property) in the grid's OnDataBound event. For example:

protected void grid_DataBound(object sender, EventArgs e)
{
    grid.TopPagerRow.Visible = true;
}
like image 85
David M Avatar answered Oct 06 '22 15:10

David M


I found that this happens if you are trying to force a column to be invisible. for example if you use:

e.Row.Cells[0].Visible = false;

You can cause the pager to render invisible.

You should use this code instead:

if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header) { e.Row.Cells[0].Visible = false; }

like image 29
John Rossitter Avatar answered Oct 06 '22 16:10

John Rossitter