title: ASP.NET Gridview paging does not work if the grid is not loaded during Page_load. Tried all methods
body: <p>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.</p>
  
  <p>I have the following on page_indexing properly.</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>I even tried by adding the databind() code inside the pageindexchanging as suggested in other threads but that didn't make any difference.</p>
  
  <p>The only way I could get this going was by populating/loading the grid on page_load. I have to assign datasource &amp; databind it every time irrespective of even postbacks. I tried IsNotpostback then the paging failed again</p>
  
  <p>Why does gridview needs loading on page_load every time if the paging needs to work properly?</p>