views:

24

answers:

2

Hi,

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?

A: 

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.

Andrew Barber
Yep, after you bind the MS grid to data inside the button click handler and then page, you have to change the page index and rebind it again in order to update its state. Same with sorting, editing, etc.
Dick Lampard
I did the binding after assigning the new page index. still not working. did datasource assignment and databind() call on pageindexing event :(
Enggr
A: 

I did the binding after assigning the new page index. still not working. did datasource assignment and databind() call on pageindexing event :( –

Enggr