Use aspnetpager and viewstate to implement Asp.net paging respectively

Source: Internet
Author: User

The following describes two types of pages: aspnetpager and viewstate.

 

I. Usage of aspnetpager

1. Copy aspnetpager. DLL to the bin directory, go to the toolkit> select items> browse, and add references under bin.

2. Drag an aspnetpager from the toolbox and modify the following attributes:

Pagesize -- number of records displayed per page

Custominfohtml -- custom display text, usually "% currentpageindex % PAGE % pagecount % PAGE"

Showcustominfosection -- display the current page and total page number. The value is never, right, left.

Alwaysshow -- always display paging controls

Pageindexboxtype -- specify the display type of the page index box. The value is a text box and the drop-down list box is used.

Showpageindexbox -- specify the display mode of the index box on the page. The value is always, never, and auto.

Textafterpageindexbox-text content after the page index box, usually "page"

Textbeforepageindexbox -- the text content before the page index box, usually "go"

 

Shown below

 

 

3. Write the following in the pagechanged event of aspnetpager:Code:

Protected void aspnetpager1_pagechanged (Object sender, eventargs E)
{
Databind ();
}

 

Private void databind ()
{
Pageddatasource PPS = new pageddatasource ();
PPS. datasource = List <t>;
PPS. allowpaging = true;
PPS. pagesize = aspnetpager1.pagesize; // aspnetpager1 is ID
Aspnetpager1.recordcount = PPS. performancecount;
PPS. currentpageindex = aspnetpager1.currentpageindex-1;
Gridview1.datasource = PDS; // bind to the gridview
Gridview1.databind ();
}

 

 

Ii. viewstate

1. Four buttons trigger the same click event as follows:

Protected void button#click (Object sender, eventargs E)
{

Pageddatasource PPS = new pageddatasource ();

PDS. datasource = Ds. Tables [0]. defaultview;
PPS. allowpaging = true;
PPS. pagesize = 10;

Button lB = (button) sender;
Int page = 0;
Switch (Lb. Text)
{
Case "Homepage ":
Viewstate ["vs"] = 0;
Break;
Case "Next ":
If (viewstate ["vs"]! = NULL)
{
Page = convert. toint16 (viewstate ["vs"]);
}
If (page <PPS. pagecount-1)

Page ++;
Viewstate ["vs"] = page;
Break;
Case "previous ":
If (viewstate ["vs"]! = NULL)
{
Page = convert. toint16 (viewstate ["vs"]);
}
If (page> 0)

Page --;
Viewstate ["vs"] = page;
Break;
Case "last page ":
Viewstate ["vs"] = maid. pagecount-1;
Break;
}

Databind ();

}

 

Private void databind ()
{

Int page = 0;
If (viewstate ["vs"]! = NULL)
{
Page = convert. toint16 (viewstate ["vs"]);
}
Status = "<font color = green> current page + (page + 1) +"/"+ PAM. pagecount +" page </font> ";
PPS. currentpageindex = page;
Repeater1.datasource = PPS;
Repeater1.databind ();

 

}

 

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.