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 

代码:

 

代码
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

 

 

 

 

 

posted @ 2010-03-17 17:43  痴呆先生、  阅读(442)  评论(1编辑  收藏  举报