asp.net 分页

使用简单的分页类:

引用:

Show(CurPage, int.Parse(count.ToString()), 15, newurlname, "");

newurlname为变量,当前地址栏无传值时,newurlname应赋值为“?page=”

如果有存在页面传值,比如test.aspx?test=test,则newurlname应赋值为“?test=test&page=”

 CurPage为:当前页的数字,如第二页,则值为2

 int.Parse(count.ToString())  这个是总的页数,对了,在这里要说明下,这里是用PagedDataSource分页的,上面的类只是输出连接而已,如:“1 2 3 4 5 6 7 8 9......99”

"15"则为你当前要显示的连接数如果为15的话,则输出样式为:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15........99 

代码:

 

ExpandedBlockStart.gif 代码
 
   
1 public static string Show( int curp, int pagecount, int maxcount, string leftstr, string rightstr)
2 {
3 StringBuilder str = new StringBuilder();
4 int leftMin, RightMax;
5 if (maxcount % 2 == 0 )
6 {
7 leftMin = curp - intplus(maxcount);
8 RightMax = curp + intplus(maxcount) + 1 ;
9 }
10 else
11 {
12 leftMin = curp - intplus(maxcount);
13 RightMax = curp + intplus(maxcount);
14 }
15 if (leftMin < 2 )
16 leftMin = 1 ;
17
18 if (RightMax > pagecount)
19 RightMax = pagecount;
20 if (curp < intplus(maxcount) && pagecount >= maxcount)
21 {
22 leftMin = 1 ;
23 RightMax = maxcount;
24 }
25 if (leftMin > 2 )
26 str.Append( " <a class=\ " page\ " href=\ "" + leftstr + " 1 " + rightstr + " \ " title=\ " 第1页\ " >1</a>... " );
27 if (leftMin == 2 )
28 str.Append( " <a class=\ " page\ " href=\ "" + leftstr + " 1 " + rightstr + " \ " title=\ " 第1页\ " >1</a> " );
29
30 for ( int i = leftMin; i <= RightMax; i ++ )
31 {
32 if (i == curp)
33 str.Append( " <a class=\ " pagenow\ " > " + i.ToString() + " </a> " );
34 else
35 str.Append( " <a class=\ " page\ " href=\ "" + leftstr + i.ToString() + rightstr + " \ " title=\ " " + i.ToString() + " 页\ " > " + i.ToString() + " </a> " );
36 }
37 if (RightMax < pagecount - 1 )
38 str.Append( " ...<a class=\ " page\ " href=\ "" + leftstr + pagecount.ToString() + rightstr + " \ " title=\ " " + pagecount.ToString() + " 页\ " > " + pagecount.ToString() + " </a> " );
39 if (RightMax == pagecount - 1 )
40 str.Append( " <a class=\ " page\ " href=\ "" + leftstr + pagecount.ToString() + rightstr + " \ " title=\ " " + pagecount.ToString() + " 页\ " > " + pagecount.ToString() + " </a> " );
41 return str.ToString();
42 }
43 public static int intplus( int i)
44 {
45 if (i % 2 == 0 )
46 return i / 2 ;
47 else
48 return (i - 1 ) / 2 ;
49 }

 24款超实用的Web 2.0风格翻页代码,可以结合上面的类进行使用,比如该类返回的是字符串,你可以把它复制到Label控件上,然后在Label控件外加一个DIV,并在"24款超实用的Web 2.0风格翻页代码.zip"中找到喜欢的样式,直接设置DIV的class即可.很方便.

 24款超实用的Web风格翻页代码.zip

 

 下面是asp.net中引用dll 实现分页,暂时只有压缩包.不经常用,所以没有介绍怎么具体用.

分页.rar

 

 

 

 

 

转载于:https://www.cnblogs.com/mrguo/archive/2010/03/17/1688363.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值