The GridView paging problem in asp.net _ Practical tips

Source: Internet
Author: User

The example in this article describes the GridView paging problem in asp.net. Share to everyone for your reference. The specific analysis is as follows:

In ASP.net, the GridView is often used for pagination, and in general, there is no problem with the data source control that is brought with Visual Studio.
But if you set the data source for the GridView in code, the first page of the GridView appears normal, and if you click on the second page, you will often see the following error
Tip: The GridView "gridview_test" fires an unhandled event "pageindexchanging".

The solution to this problem is:

1. In the. aspx design page of the GridView, add

Copy Code code as follows:
Allowpaging= "true"
And
Copy Code code as follows:
Onpageindexchanging= "Gridview_test_pageindexchanging";

That
Copy Code code as follows:
<asp:gridview id= "Gridview_module" runat= "Server" allowpaging= "true" onpageindexchanging= "Gridview_test_" Pageindexchanging ">

2. In the. Aspx.cs page, add the following code:

Copy Code code as follows:
protected void Gridview_test_pageindexchanging (object sender, Gridviewpageeventargs e)
{
Gridview_test_pageindex = E.newpageindex;
Gridview_test. Datasource= "* *"/Set Data source
Gridview_test. DataBind ();
}

3, run the program, the page will not be wrong.

I hope this article will help you with the ASP.net program design.

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.