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 ();
}