Introduction
If you are experiencing that GridView
paging takes
two clicks to work instead of 1 then please read on.
Background
This problem may effect only selected people and also happens due to other reasons as well which I am not going to cover in this article.
Using the code
In one of the projects I did; I noticed that paging of one of the GridView
controls was taking
two clicks instead of one to work.
I debugged the application and it was posting back and there was not a single difference between the two clicks but still the paging was working on the second click.
Then I noticed the following piece of code:
protected void gvUsers_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
BindGrid();
gvUsers.PageIndex = e.NewPageIndex;
}
So effectively I was binding the grid first and then issuing a new index.
I changed the order of issuing new index and binding statement.
protected void gvUsers_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvUsers.PageIndex = e.NewPageIndex;
BindGrid();
}
and voila!
The paging started working just by a single click instead of two.
So the Tip is to issue a new index before re-binding the grid.
Hope this helps :-)