ASP.net Gridview Paging doesin't work inside UpdatePanel

自闭症网瘾萝莉.ら 提交于 2019-12-05 08:19:08

The solution is that you should refill the dataset which is used to populate the gridview, each time your page index is changed. By this way, you could ensure that in each seperate postback which has been triggered by the gridview page number, results will be populated.

I just tried that above code. I had same issue and now it is working just fine.

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{ 
    GridView1.PageIndex = e.NewPageIndex;         
    GridView1.DataBind(); 
    //  UpdatePanel2.Update();   <-- Remove this line from your code.
} 

I have GridView inside update panel. Did you write your event PageIndexChanging in your .aspx file also?

Hope this helps.

Further research:

http://msdn.microsoft.com/en-us/library/cc295545.aspx

Controls that are not compatible with UpdatePanel controls

The following ASP.NET controls are not compatible with partial-page updates, and are therefore not designed to work inside an UpdatePanel control:

  • GridView and DetailsView controls when their EnableSortingAndPagingCallbacks property is set to true. The default is false.

To do it, you have to re set the datasource in the page index change event. The performance will be lower but that's the way you can make it works.

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.DataSource = ;//Set again the datasource
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataBind();
    UpdatePanel2.Update();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!