Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Sir..

I have a gridview control in asp.net .It have a edit link button.when i click on this other page is open.I am using inbuilt paging in grid view .Suppose i have 5 page in it.My problem is that when i go from 2,3,4 page and go back from other page to page in which page have grid view by default it display th content of first page not display the content of recently selected page.

Thanks sir..

Randeep Chauhan
Posted
Comments
Parwej Ahamad 25-Jun-11 4:49am    
Have you implemented gridView_PageIndexChanging event? and in this even are you setting current page index?
OR
Please make sure, on page load event are you binding under IsPostBack check like:
If(!IsPostback)
Bind grid

Thanks,
Parwej

Do the following.

1. Bind the GridView in Page_Load event.
2. Implement PageIndexChanging event of the GridView.

C#
protected void Page_Load(object sender, System.EventArgs e)
{
    if (!IsPostBack) {
        bindControls();
    }
}

protected void GridView1_PageIndexChanging(object sender, System.Web.UI.WebControls.GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    bindControls();
}

private void bindControls()
{
    BusinessLogicFacade businessLogic = new BusinessLogicFacade();// Change to your data source class and bind the GridView.
    GridView1.DataSource = businessLogic.GetData();
    GridView1.DataBind();
}
 
Share this answer
 
VB
Protected Sub grdGoods_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdGoods.PageIndexChanging
    grdGoods.PageIndex = e.NewPageIndex
    grdGoods.DataSource =  DataTable 'that is populated by a query
    grdGoods.DataBind()
End Sub
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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