曾经在做wap项目的时候使用SQL 语句来实现分页,但是每按下一页或跳转的时候会再次读取数据库,且查询语句比较复杂(忘记怎么写了..需要的自己百度就一堆^^),导致查询速度超慢....(存储模式不会╮(╯_╰)╭..没做这方面的测试)
通过程序对需要分页的数据进行操作,就不需要花费过多的时间对数据库进行查询,但是服务器压力增大...对于少量数据来说依然比较迅速..同时,对于对搜索结果,这样的分页处理则更加方便+准确(以前尝试过SQL的搜索+分页处理...慢到变态..并且出错...o(╯□╰)o)
Code
1 public int ListPerPage=10; //多少行一页
2
3 /**//// <summary>
4 /// 分页
5 /// </summary>
6 /// <param name="bookList">页面内容</param>
7 /// <param name="currentPage">当前页码</param>
8 public void PageSort(List<TestClass> list, int currentPage)
9 {
10 if (list.Count <= 0)
11 return;
12
13 int num = (currentPage - 1) * ListPerPage;
14
15 for (int i = num; i < num + ListPerPage; i++)
16 {
17 if (i >= list.Count)
18 break;
19
20 wap.SimpleText((i + 1) + ".");
21 wap.A("xxx.aspx?id=" + list[i].ID, true);
22 wap.SimpleText(list[i].Name);
23 wap.A("", false);
24 wap.BR();
25 }
26 }
27
28 /**//// <summary>
29 /// 显示第几页
30 /// </summary>
31 /// <param name="totalPage">总页数</param>
32 /// <param name="currentPage">当前页</param>
33 /// <param name="currentUrl">当前URL</param>
34 public void PageLink(int totalPage, int currentPage, string currentUrl)
35 {
36
37 if (currentPage != totalPage)
38 {
39 wap.A(currentUrl + "p=" + (currentPage + 1), true);
40 wap.SimpleText("下页");
41 wap.A("", false);
42 }
43 else
44 {
45 wap.SimpleText("下页");
46 }
47
48 wap.SimpleText(" ");
49
50 for (int i = 0; i < 5; i++)
51 {
52 int page;
53 if (currentPage % 5 != 0)
54 page = currentPage - (currentPage % 5) + i + 1;
55 else
56 page = currentPage - 5 + i + 1;
57
58 if (page > totalPage)
59 break;
60
61 if (page == currentPage)
62 {
63 wap.SimpleText(currentPage.ToString());
64 }
65 else
66 {
67 wap.A(currentUrl + "p=" + page, true);
68 wap.SimpleText(page.ToString());
69 wap.A("", false);
70 }
71 wap.SimpleText(" ");
72 }
73
74 if (currentPage != 1)
75 {
76 wap.A(currentUrl + "p=" + (currentPage - 1), true);
77 wap.SimpleText("上页");
78 wap.A("", false);
79 }
80 else
81 {
82 wap.SimpleText("上页");
83 }
84
85 wap.BR();
86
87 wap.SimpleText("[" + currentPage + "/" + totalPage + "]页");
88 wap.SimpleText(" to");
89 wap.Input("page", "", 3, "");
90 wap.SimpleText("页");
91
92 wap.A(currentUrl + "p=$(page)", true);
93 wap.SimpleText("[转到]");
94 wap.A("", false);
95 wap.BR();
96 }
97
1 public int ListPerPage=10; //多少行一页
2
3 /**//// <summary>
4 /// 分页
5 /// </summary>
6 /// <param name="bookList">页面内容</param>
7 /// <param name="currentPage">当前页码</param>
8 public void PageSort(List<TestClass> list, int currentPage)
9 {
10 if (list.Count <= 0)
11 return;
12
13 int num = (currentPage - 1) * ListPerPage;
14
15 for (int i = num; i < num + ListPerPage; i++)
16 {
17 if (i >= list.Count)
18 break;
19
20 wap.SimpleText((i + 1) + ".");
21 wap.A("xxx.aspx?id=" + list[i].ID, true);
22 wap.SimpleText(list[i].Name);
23 wap.A("", false);
24 wap.BR();
25 }
26 }
27
28 /**//// <summary>
29 /// 显示第几页
30 /// </summary>
31 /// <param name="totalPage">总页数</param>
32 /// <param name="currentPage">当前页</param>
33 /// <param name="currentUrl">当前URL</param>
34 public void PageLink(int totalPage, int currentPage, string currentUrl)
35 {
36
37 if (currentPage != totalPage)
38 {
39 wap.A(currentUrl + "p=" + (currentPage + 1), true);
40 wap.SimpleText("下页");
41 wap.A("", false);
42 }
43 else
44 {
45 wap.SimpleText("下页");
46 }
47
48 wap.SimpleText(" ");
49
50 for (int i = 0; i < 5; i++)
51 {
52 int page;
53 if (currentPage % 5 != 0)
54 page = currentPage - (currentPage % 5) + i + 1;
55 else
56 page = currentPage - 5 + i + 1;
57
58 if (page > totalPage)
59 break;
60
61 if (page == currentPage)
62 {
63 wap.SimpleText(currentPage.ToString());
64 }
65 else
66 {
67 wap.A(currentUrl + "p=" + page, true);
68 wap.SimpleText(page.ToString());
69 wap.A("", false);
70 }
71 wap.SimpleText(" ");
72 }
73
74 if (currentPage != 1)
75 {
76 wap.A(currentUrl + "p=" + (currentPage - 1), true);
77 wap.SimpleText("上页");
78 wap.A("", false);
79 }
80 else
81 {
82 wap.SimpleText("上页");
83 }
84
85 wap.BR();
86
87 wap.SimpleText("[" + currentPage + "/" + totalPage + "]页");
88 wap.SimpleText(" to");
89 wap.Input("page", "", 3, "");
90 wap.SimpleText("页");
91
92 wap.A(currentUrl + "p=$(page)", true);
93 wap.SimpleText("[转到]");
94 wap.A("", false);
95 wap.BR();
96 }
97
看不懂的代码自己幻想吧(O(∩_∩)O)...大概就是显示文本和链接的东西.
这里包括了分页和导航2部分...把所需的全部数据写入缓存,再通过简单的调用即可实现分页..方便快捷,简单易用..(囧TL)