Recently, I encountered a strange problem with my website. During the DataGrid paging, I was unable to respond to the pageindexchanged event.
I have read a lot about this.ArticleBut there is still no solution. Found the crux of the problem in the discussion with others
FirstCodePost:
The following is the HTML code of the IRD control (excluding field binding)
<Asp: dataGrid id = "searchgrid" runat = "server" width = "100%" autogeneratecolumns = "false" enableviewstate = "true" allowpaging = "true" pagesize = "3" pagerstyle-mode = "numericpages" pagerstyle-horizontalalign = "right" pagerstyle-pagebuttoncount = "5" onpageindexchanged = "searchgrid_pageichanged">
The following is the post code:
Private sub page_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load
If not ispostback then
Bindgrid ()
End if
End sub
Public sub searchgrid_pageichanged (byval s as object, byval e as datagridpagechangedeventargs)
Searchgrid. currentpageindex = E. newpageindex
Bindgrid ()
End sub
Public sub bindgrid ()
Searchgrid. datasource = (bind your data source)
Searchgrid. databind ()
End sub
For the code above, you can get the correct display result and page number when loading the page for the first time, but you cannot respond to the paging event when switching the page.
TrackedProgramWe found that pageload is called every time the page is switched. After I remove databind from is notpostback, the page is normal.
This means that the data will be re-loaded to the DataGrid every time on the send-back page, and the enableviewstate is set to false for the DataGrid.
The data in the DataGrid is not retained. As a result, the data in the DataGrid can be rebound only when it is loaded.
Therefore, enableviewstate is set to true to solve the problem.