Click here to Skip to main content
15,887,746 members
Articles / Web Development / ASP.NET
Tip/Trick

GridView paging takes two clicks instead of one

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
17 Apr 2012CPOL 25.2K   1   4
GridView paging takes two clicks (solved).

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:

C#
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.

C#
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 :-)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionThanks you, this saved me a lot of issues Pin
Member 148535274-Jun-20 6:08
Member 148535274-Jun-20 6:08 
GeneralMy vote of 5 Pin
Pritesh Aryan31-Jul-12 0:37
Pritesh Aryan31-Jul-12 0:37 
QuestionSimiliar problem with editing Pin
Attila Buj24-Jul-12 23:51
Attila Buj24-Jul-12 23:51 
GeneralThanks Pin
Member 846268417-Apr-12 13:30
Member 846268417-Apr-12 13:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.