DataGrid paging problem: unable to respond to pageindexchanged event

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.