ASP.NET Gridview paging does not work if the grid is not loaded during Page_load. Tried all methods
I have a gridview which I load with data on click of a button. For some reason the paging did not work. The paging number shows up but clicking on page # 2, 3 or 4 does not take you anywhere. the grid just disappears on clicking them. right after that when i click the button to generate the grid, the grid came up this time the gird is on page 2 or 3 instead of 1.
I have the following on page_indexing properly.
Protected Sub GV_Document_Hide_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GV_PSIDocument_Hide.PageIndexChanging
GV_Document_Hide.PageIndex = e.NewPageIndex
End Sub
I even tried by adding the databind() code inside the pageindexchanging as suggested in other threads but that didn't make any difference.
The only way I could get this going was by populating/loading the grid on page_load. 开发者_运维百科I have to assign datasource & databind it every time irrespective of even postbacks. I tried IsNotpostback then the paging failed again
Why does gridview needs loading on page_load every time if the paging needs to work properly?
It doesn't need Page_Load every time; but when you change the page, you do need to re-bind to the data source so it can load its new records for the new page. You can do that in the event handling the page changing, if you like.
Do you use Update panels in your page? Obout grids paging doesn't work with MS UpdatePanel. You should use their own panel: https://www.obout.com/ajaxpage/cp_howitworks.aspx If it doesn't work try also to set serialize=false.
精彩评论