Aspnetpager detailed usage of pagination (ASP. NET)

Source: Internet
Author: User

1. "Add AspNetPager.dll File"

2. "How to use"

      Public StaticDataTable Getrecord (Systemmodel.pager MT,ref intTotalpage,ref intTotalrecord) {            stringSortType = Mt. SortType = =1?"ASC":"desc"; //Query total number of bars            string_strcountsql ="Select COUNT ("+ Mt. PrimaryKey +") from"+ Mt. TableName +"where"+Mt.            Where; string_strpagesql ="Select Top"+ Mt. PageSize +" "+ Mt. Filedlist +" from"+ Mt. TableName +"where"+ Mt. PrimaryKey +"Not in (select Top"+ Mt. PageSize * (Mt. PageIndex-1) +" "+ Mt. PrimaryKey +" from"+ Mt. TableName +"where"+ Mt. Where +"Order by"+ Mt. Order + SortType +","+ Mt. PrimaryKey +" "+ SortType +") and"+ Mt. Where +"Order by"+ Mt. Order + SortType +","+ Mt. PrimaryKey +" "+SortType; if(Mt. PageIndex = =1) {_strpagesql="Select Top"+ Mt. PageIndex * Mt. PageSize +" "+ Mt. Filedlist +" from"+ Mt. TableName +"where"+ Mt. Where +"Order by"+ Mt. Order + SortType +","+ Mt. PrimaryKey +" "+SortType; } DataSet DS=DBUtility.AccessHelper.Query (_strpagesql); Totalrecord=int. Parse (DBUtility.AccessHelper.GetSingle (_strcountsql).            ToString ()); Totalpage= Totalrecord% Mt. PageSize = =0? TOTALRECORD/MT. PAGESIZE:TOTALRECORD/MT. PageSize +1; returnDs. tables[0]; }



You can also use stored procedure paging, where the parameters to return the total number of pages, the current page.

Create procedureHome (@pagesize int,@pageindex int,@docount bit) asif(@docount=1)Select Count(*) fromBinfoElsebegin  withTemptbl as (SELECTRow_number () Over(ORDER  byTimedesc) asRow,*  frombinfo O)SELECT *  fromTemptblwhereRowbetween(@pageindex-1)*@pagesize+1  and(@pageindex-1)*@pagesize+@pagesizeEnd

3. "Use in the page"

INDEX.ASX page:

 <Webdiyer:aspnetpagerID= "Pager22"runat= "Server"Alwaysshow= "true"font-size= "12px"Currentpagebuttonclass= "CPB"Firstpagetext= "Home"Lastpagetext= "Last"NextPageText= "Next Page"Prevpagetext= "Previous page"custominfotextalign= "Right"Showpageindexbox= "Never"showcustominfosection= "Left"Centercurrentpagebutton= "True"Showfirstlast= "true"Reverseurlpageindex= "True"Direction= "LeftToRight"Width= "100%"onpagechanging= "Pager_pagechanging"ForeColor= "Black"Numericbuttoncount= "+">                                    </Webdiyer:aspnetpager>

Specific parameters, you can check the relevant properties.

Index.aspx.cs

Systemmodel.pager mt = new Systemmodel.pager (); Mt.            PageIndex = PageIndex; Mt.            PageSize = number of pages; Mt.            TableName = table name; Mt.            Filedlist = The contents of the query, such as *; Mt.            PrimaryKey = primary key; Mt.            Where = condition; if (httpcontext.current.request["id"]! = NULL) {Mt. Where = Mt. Where + "and fid=" + Int. Parse (httpcontext.current.request["id").            ToString ()); } Mt.            order = sort field; Mt.            SortType = Sort Method (1 or 2); Mt.            Recordercount = 0;            int totalpage = 1;            int totalrecord = 0;            Dtnews = SystemBLL.Pager.GetRecord (MT, ref totalpage, ref Totalrecord); if (DtNews.Rows.Count<1) {return; } DataView DV= Dtnews.defaultview; PagedDataSource PDS= newPagedDataSource (); Pds. DataSource= DV; PDS. AllowPaging= true; PDS. CurrentPageIndex= Pager22.currentpageindex-1; Pds. PageSize= pager22.pagesize; This . Pager22.pagesize= Mt.            PageSize; This . Pager22.recordcount= Totalrecord; This . Pager22.custominfohtml= string. Format ("Total{0} page, current {1} page, total {2} records ", Totalpage, PageIndex, Totalrecord); if (Totalrecord <= Mt. PageSize){this.  Pager22.            Style.add ("Display", "none"); } else {this.  Pager22.            Style.add ("Display", "block"); }

There are only a few properties that are commonly used, as well as custom URLs like CSS.

also supports MVC

For more properties, see here: http://www.webdiyer.com/aspnetpager/

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.