Aspnetpager How to use pagination controls

Source: Internet
Author: User

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"%>"">"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 Code

Red 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 Code

Code reference:

Aspnetpager How to use pagination controls

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