Gridview pagination + Style

Source: Internet
Author: User

This is the front-end code of the gridview page.

Allowpaging = "true" whether automatic Paging

Pagesize = "10" after 10 data entries

Autogeneratecolumns = "false" cancel the built-in table mode

Onpageindexchanging = "gvwdesignationname_pageindexchanging"PageindexchangingEvent.

When more than 10 pieces of data are automatically paged, the <pagertemplate> </pagertemplate> Control in the gridview is displayed.

The gvwdesignationname_pageindexchanging event is to obtain the Foreground Data, assign the value to the corresponding gridview attribute, and re-bind the data to jump to the corresponding page number.

<HTML xmlns = "http://www.w3.org/1999/xhtml"> 

This is the background code

Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; namespace test2 {public partial class WebForm1: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {BinData () ;}// bind private void BinData () {Exam a = new Exam (); GridView1.DataSource =. listExam (); GridView1.DataBind ();} // pagination protected void handle (object sender, GridViewPageEventArgs e) {// you can get the control GridView theGrid = sender as GridView; int newPageIndex = 0; if (e. newPageIndex =-3) {// click the Go button TextBox txtNewPageIndex = null; // compared with the DataGrid, The GridView provides For more APIs, you can use BottomPagerRow or TopPagerRow to retrieve paging blocks. Of course, HeaderRow and FooterRow GridViewRow pagerRow = theGrid. BottomPagerRow; if (pagerRow! = Null) {// obtain the text control txtNewPageIndex = pagerRow. FindControl ("txtNewPageIndex") as TextBox;} if (txtNewPageIndex! = Null) {// obtain the index newPageIndex = int. parse (txtNewPageIndex. text)-1 ;}} else {// click another button newPageIndex = e. newPageIndex;} // prevents the new index from overflowing with newPageIndex = newPageIndex <0? 0: newPageIndex; newPageIndex = newPageIndex> = theGrid. PageCount? TheGrid. PageCount-1: newPageIndex; // get the new value theGrid. PageIndex = newPageIndex; // BinData ();}}}

This is the code paging Effect

 

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.