Click here to Skip to main content
15,671,597 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
i am using a there are many pages in datagrid if i am in 5th page...after postback i want the datagrid to retain in same 5th page after postback....plz help me
Sinisa Hajnal 15-Sep-14 9:27am    

1 solution

Store your Current page number in Session

protected void GridViewIndexChanging(object sender, GridViewPageEventArgs e)
        myGridView.PageIndex = e.NewPageIndex;
        Session["pageNumber"] = e.NewPageIndex;
        //whatever your page index changing does...

Call the session value in page load

if (!IsPostBack)
         if (Session["pageNumber"] != null)
             GridViewIndexChanged(myGridView, new GridViewPageEventArgs((int)Session["pageNumber"]));
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900