猿问

老大,问个c#分页算法的问题?

老大,问个c#分页算法的问题


拉丁的传说
浏览 474回答 1
1回答

繁星点点滴滴

好象没太多意义,那个currint应该就是10除2的结果,整个代码就大概是要显示从currentPage-5到currentPage+5之间这10页,就相当于1234567891011121314151617string&nbsp;output&nbsp;=&nbsp;"";int&nbsp;num&nbsp;=&nbsp;10;if&nbsp;(totalPages&nbsp;<&nbsp;num)&nbsp;num&nbsp;=&nbsp;totalPages-1;//如果总页数不够10int&nbsp;currint&nbsp;=&nbsp;num&nbsp;/&nbsp;2;int&nbsp;min&nbsp;=&nbsp;(currentPage&nbsp;>currint&nbsp;?&nbsp;currentPage&nbsp;-&nbsp;currint&nbsp;:&nbsp;1);//起始int&nbsp;max&nbsp;=&nbsp;(currentPage&nbsp;+&nbsp;currint&nbsp;>&nbsp;totalPages&nbsp;?&nbsp;totalPages&nbsp;:&nbsp;currentPage&nbsp;+&nbsp;currint);//结束&nbsp;//为避免currentpage小于5时,以及避免最后几页显示不到10项,加上下面两行if&nbsp;(max&nbsp;<=&nbsp;num)&nbsp;max&nbsp;=&nbsp;num+1;if&nbsp;(max&nbsp;-&nbsp;min&nbsp;<&nbsp;num)&nbsp;min&nbsp;=&nbsp;max&nbsp;-&nbsp;num;&nbsp;if&nbsp;(currentPage&nbsp;>&nbsp;totalPages)&nbsp;currentPage&nbsp;=&nbsp;totalPages;for(int&nbsp;i=min;i<max;i++){string&nbsp;css=(i==currentPage?"cpb":"pageLink");output.AppendFormat("<a&nbsp;class='{4}'&nbsp;href='{0}?pageIndex={1}&pageSize={2}'>{3}</a>&nbsp;",&nbsp;redirectTo,&nbsp;i,&nbsp;pageSize,&nbsp;i,css);}&nbsp;附上修改前后的图(最前的数字为当前页,为简单我直接把当前页用[]标出了)
随时随地看视频慕课网APP
我要回答