DataGrid Paging problem

Source: Internet
Author: User
datagrid| Pagination | The problem with the recent Web site has encountered a strange problem, in the DataGrid for paging, unable to respond to the PageIndexChanged event.
I have also consulted a lot of articles about this, but I still haven't got the solution. Found the crux of the discussion with others

First, I'll post the code here:

The following is the HTML code for the Datagird control (does not contain field bindings)

<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" >

Here 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, the first load page can get the correct display results and number of pages, but when you switch pages, you can't respond to paging events.

After the tracking program found that the switch page to call pageload every time, I moved DataBind out of is notpostback, pagination can be normal

Shows that the DataGrid is loaded with data every time it is sent back, taking into account that the DataGrid is set to EnableViewState false

The DataGrid data is not preserved, causing the DataGrid to be unbound only after each load to achieve a normal paging status.

Therefore, setting the EnableViewState to true solves 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.