Paging not working in asp.net gridview inside AJAX updatepanel

雨燕双飞 提交于 2019-12-05 05:06:22

In PageIndexchanging event, where you bind data to grid, make sure, data is again fetched from the DB I don't know what that means; my data was being bound as demonstrated above.

It means that you need to fetch your data again in your code behind page. You are using a SQLdatasource in your design/html page, so you need to remove that and use a SQL Connection, SQL Command, etc. to fetch your data and then set that as your control's datasource.

Something like below:

http://www.aspnettutorials.com/tutorials/database/db-grid-aspnet2-vb.aspx

Your code should look something like this

Protected Sub Page_Load(...)
   gvEvents.PageIndex = 0
   LoadData();// loads initial data
end sub

private sub LoadData()
 '' do your SQL Conn and Command here
 '' set your datasource of gridview here
end sub

Protected Sub gvEvents_PageIndexChanging(...) Handles gvEvents.PageIndexChanging
  gvEvents.PageIndex = e.NewPageIndex
  LoadData()
  gvEvents.DataBind()
end sub

For anyone who stumbles across this issue, I encountered it this AM and this post was misleading (atleast for my scenario). For me, I simply had to add a PageIndexChanging Event as a trigger for my datagrid for the updatepanel trigger's, and it resolved my issue.

Controls that Are Not Compatible with UpdatePanel Controls

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

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

http://www.asp.net/Ajax/Documentation/Live/overview/UpdatePanelOverview.aspx

Just update the AJAX Panel after databind().

assume id of the Update Panel is AJAXPanel

Protected Sub gvEvents_PageIndexChanging(...) Handles gvEvents.PageIndexChanging             
     gvEvents.PageIndex = e.NewPageIndex
     LoadData()
     gvEvents.DataBind()
     // The below line refreshes the update panel..  
     AJAXPanel.Update()
end sub
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!