Feel the convenience of the DataGrid for Data Operations (3)

Source: Internet
Author: User

Section 3: Fast Paging
In section 2, I learned how to quickly and conveniently customize the appearance of the DataGrid. In this section, I learned how to quickly paging data.
When querying a database, we usually do not use a page to display all the data, but display the data by page. I remember that in asp, it was very troublesome to compile a page by page. When I learned how to use DataGrid to Render data, I was excited because it was so simple to create data paging.
Enable the property generator (or modify the attributes of the "pagination" class). At this time, you must select the "pagination" branch on the left. On the right side, select "allow pagination" and set the number of entries displayed on each page, the position and name of the page navigation bar. Do you think this is okay? I thought it was okay at first, but when I ran the program, I found that there was no response after clicking the navigation bar. This is because we need to write several codes to complete this operation.
Select the DataGrid, select the event tag in the tag at the top of the Property Window (because we want to create a page flip event), find the "PageIndexChanged" event, and write the following code:
Private void DataGrid1_PageIndexChanged (object source, System. Web. UI. WebControls. DataGridPageChangedEventArgs e)
DataGrid1.CurrentPageIndex = e. NewPageIndex;
BindGrid ();


Ha, good "long" code!
DataGrid1 has an attribute called CurrentPageInde to specify the page to display. The "e" parameter of the "PageIndexChanged" event can tell DagtaGrid1 which page to display.
BindGrid () Is the function I used to bind data in section 1. You don't need to write it again. Check the article in section 1.
That's easy. Don't believe it. Try it.

Related Article

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.