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!
Explanations:
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.