Click here to Skip to main content
Click here to Skip to main content

GridView paging takes two clicks instead of one

, 17 Apr 2012
Rate this:
Please Sign up or sign in to vote.
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:

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 Smile | :)

License

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

About the Author

RobertDinaro
Software Developer
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 PinmemberPritesh Aryan31-Jul-12 0:37 
QuestionSimiliar problem with editing PinmemberAttila Buj24-Jul-12 23:51 
GeneralThanks PinmemberMember 846268417-Apr-12 13:30 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 17 Apr 2012
Article Copyright 2012 by RobertDinaro
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid