Paging components:
/// <summary> ///Paging Component/// </summary> Public classPagerhelper {/// <summary> ///Paging Component/// </summary> /// <param name= "urlfmt" >URL format: newsindex_{pagenum}.shtml</param> /// <param name= "TotalSize" >total number of bars</param> /// <param name= "pagesize" >number of bars per page</param> /// <param name= "CurrentPage" >Current Page</param> /// <returns>Sub-page subscript</returns> Public StaticRawstring Pager (stringURLFMT,LongTotalSize,LongPageSizeLongcurrentpage) { //urlfmt = newscontroller.ashx?action=list&pagenum={pagenum}//newsindex_{pagenum}.shtml LongTotalpagecount = (Long) math.ceiling ((TotalSize *1.0/pagesize));//Total Pages LongPagebuttom =4;//8 Page Labels LongFirstPage = Math.max (Currentpage-pagebuttom,1);//first page label LongEndPage = math.min (currentpage + pagebuttom, totalpagecount);//last page labelStringBuilder SB=NewStringBuilder (); if(firstpage>1)//If you do not traverse to the first page { stringurl = urlfmt.replace ("{Pagenum}","1"); Sb. Append ("<li><a href= '"). Append (URL). Append ("' > Home </a></li>"); } for(Longi = FirstPage; I <= endpage; i++) { stringurl = urlfmt.replace ("{Pagenum}", i.ToString ()); if(i = =currentpage) {sb. Append ("<li class= ' active ' ><a>"). Append (i). Append ("page </a></li>"); } Else{sb. Append ("<li><a href= '"). Append (URL). Append ("' >"). Append (i). Append ("page </a></li>"); } } if(EndPage < Totalpagecount)//If you do not traverse to the last { stringurl = urlfmt.replace ("{Pagenum}", totalpagecount.tostring ()); Sb. Append ("<li><a href= '"). Append (URL). Append ("' > Last </a></li>"); } return Newrawstring (sb.) ToString ()); } }
Press List paging One-click static:
Public voidAllnewsliststatic (HttpContext context) {#regionPress List paging one-click staticadminhelper.checkhaspower (Context,"News One-click Static"); stringCategoryidstr = context. request["CategoryID"]; intCategoryID =Volidhelper.checkstrtoint (CATEGORYIDSTR); Td_newscategory newscate= (td_newscategory) myorm_bll. Selectmodelbyid (typeof(Td_newscategory),1, CategoryID); LongPageSize =Ten;//set the number of pages per page LongTotalSize = Myorm_bll. Selectcountbyfield (typeof(Td_news),1,"categoryid="+ CategoryID);//Total number of news articles LongTotalpagecount = (Long) math.ceiling (TotalSize *1.0/pagesize);//Total Pages for(Longi =1; I <= Totalpagecount; i++)//Traverse each page { //for each page, get the news collection under that categorylist<td_news> list =NewNEWSBLL (). Selectnewsbycategoryidandrownum (CategoryID, (I-1) * pagesize +1Ipagesize); stringcshtml = razorhelper.razorparsehtml (Context,"~/news/newsliststatic.cshtml",New{CategoryID=CategoryID, CategoryName=Newscate.name, Newses=list, TotalSize=TotalSize, pagesize=pagesize, CurrentPage=i}); //Static stringPathpre = configurationmanager.appsettings["Viewstaticdirecpre"];//Path Prefix stringFullPath = pathpre + CategoryID +"\\newsIndex_"+ i +". shtml";//Full path stringDIR =Path.getdirectoryname (FullPath); if(!directory.exists (dir)) {directory.createdirectory (dir); } file.writealltext (FullPath, cshtml); } adminhelper.recordoperatelog (Context,"The News list is statically initialized with the following categories:"+newscate.name); Context. Response.Redirect ("/news/newscontroller.ashx?action=list&categoryid="+CategoryID); #endregion }
newscontroller.ashx
The statement that is queried according to RowNum:
/// <summary> ///get a news collection between the specified rownum according to the category ID in no order/// </summary> /// <param name= "CategoryID" >Category ID</param> /// <param name= "Startnum" >rownum Start number</param> /// <param name= "Endnum" >rownum End Number</param> /// <returns>Specify a news collection between RowNum</returns> PublicList<td_news> Selectnewsbycategoryidandrownum (LongCategoryIDLongStartnum,Longendnum) { stringsql =@"SELECT * FROM (select Row_number () over (order by NO ASC) Num,id,no,status,categoryid,c Reateby,createdate,lasteditby,lasteditdate,deleteby,deletedate,title,content from TD_NEWS where Status=1 and Categoryid=:categoryid) T where T.num>:startnum and T.num<:star Tnum"; DataTable DT= Oraclehelper.executereader (SQL,NewOracleParameter () {parametername =": CATEGORYID", Value =CategoryID},NewOracleParameter () {parametername =": Startnum", Value =Startnum},NewOracleParameter () {parametername =": Startnum", Value =endnum}); List<TD_NEWS> list =NewList<td_news>(); foreach(DataRow rowinchdt. Rows) {td_news NEWS=Rowtomodel (row); List. ADD (news); } returnlist; }
NewsDAL.cs
Pager sub-page