First, download AspNetPager.dll II, AspNetPager.dll copy the bin directory under the application, open the solution, reference DLL file three, add the control in the toolbar, so that you can support drag and drop use four, to use the Aspnetpager To set the most basic property Example for it:
1, the foreground display interface code default.aspx
<%@ Page language="C #"autoeventwireup="true"codefile="Default.aspx.cs"inherits="DEFAULT4"%><%@ Register assembly="Aspnetpager"Namespace="Wuqi.webdiyer"tagprefix="Webdiyer"%>"http://www.w3.org/1999/xhtml">"Head1"runat="Server"><title> AspNetPager.dll control's Paging method </title>"Form1"runat="Server"><div><table border=1><asp:repeater id="Repeater1"runat="Server"><itemtemplate><tr><td><% #DataBinder. Eval (Container.DataItem,"Osid")%></td><td><% #DataBinder. Eval (Container.DataItem,"year1")%></td><td><% #DataBinder. Eval (Container.DataItem,"month1")%></td><td><% #DataBinder. Eval (Container.DataItem,"OUTPUT1")%></td></tr></itemtemplate></asp:repeater></table><webdiyer:aspnetpager ID ="AspNetPager1"runat="Server"Width="100%"Numericbuttoncount="6"urlpaging="true"numericbuttontextformatstring="[{0}]"Custominfohtml="section <font color= ' Red ' ><b>%CurrentPageIndex%</b></font> page Total%pagecount% page display% startrecordindex%-%endrecordindex% strips"showcustominfosection=" Left"Firstpagetext="Home Page"lastpagetext="last page"nextpagetext="Next Page"prevpagetext="Previous Page"font-names="Arial"Backcolor="#F8B500"alwaysshow="true"showinputbox=" always"submitbuttontext="Jump"submitbuttonstyle="Botton"Onpagechanged="aspnetpager1_pagechanged"></webdiyer:AspNetPager></div></form></body>View CodeRed boxes are pagination related code
2, Default.aspx.cs the Code of the page
DBAccess db =NewDBAccess ();protected voidPage_Load (Objectsender, EventArgs e) {if(!Page.IsPostBack) {Bindgrid ();}}protected voidAspnetpager1_pagechanged (Objectsender, EventArgs e) {Bindgrid ();} Public voidBindgrid () { This. Aspnetpager1.recordcount =Int32.Parse (db. Getallcount (). ToString ());intPageIndex = This. Aspnetpager1.currentpageindex-1;intPageSize = This. Aspnetpager1.pagesize = -; Repeater1.datasource=db. Getcurrentpage (PageIndex, pageSize); Repeater1.databind ();} Third, the Code of the DBAccess.cs pageusingSystem.Data.SqlClient; Public classdbaccess{PrivateSqlConnection con;Private stringDBName ="tongjinet";//Create a Connection object and open Public voidOpen () {if(Con = =NULL) Con=NewSqlConnection ("server= (local); Uid=sa;pwd=sql;database="+DBName);if(Con. state = =connectionstate.closed) con. Open ();}//creates a command object and returns the object PublicSqlCommand CreateCommand (stringsqlstr) {Open (); SqlCommand cmd=NewSqlCommand (); Cmd.commandtype=Commandtype.text;cmd.commandtext=Sqlstr;cmd. Connection=con;returncmd;}//generates an object and returns the first column of the first row of the result set Public ObjectGetscalar (stringsqlstr) {SqlCommand cmd=CreateCommand (SQLSTR);Objectobj =cmd. ExecuteScalar ();//Commadnbehavior.closeconnection is associated with a database link in DataReader//Automatically close links when DataReader objects are closedreturnobj;}//executes a database query and returns a dataset [current page number, number of records per page] PublicDataSet Getcurrentpage (intPageIndex,intpageSize) {//set the import start addressintFirstPage = PageIndex *pageSize;stringSqlstr ="SELECT * from Outputsell ORDER BY osid Desc"; SqlCommand cmd=CreateCommand (sqlstr);D ataset DataSet=NewDataSet (); SqlDataAdapter DataAdapter=NewSqlDataAdapter (CMD);d ataadapter.fill (DataSet, FirstPage, PageSize,"Outputsell"); cmd. Dispose (); Close ();d ataadapter.dispose ();returnDataSet;}//get the total number of records for the query data Public ObjectGetallcount () {stringSqlstr ="Select COUNT (*) from Outputsell";Objectobj =getscalar (SQLSTR);returnobj;}//Close the database Public voidClose () {if(Con! =NULL) {con. Close ();}}//Freeing Resources Public voidDispose () {if(Con! =NULL) {con. Dispose (); Con=NULL;}}}
View CodeCode reference: http://www.cnblogs.com/taizhouxiaoba/archive/2009/03/23/1419822.html
Aspnetpager How to use pagination controls