Wap页面使用asp.net中移动控件List分页

一、创建一个类
+展开
-C#
public class navigation
{
private string _sitename, _siteurl;
public navigation(string sitename, string siteurl)
{
_sitename = sitename;
_siteurl = siteurl;
}
public string sitename { get { return _sitename; } }
public string siteurl { get { return _siteurl; } }

}

二、分页
+展开
-C#
dbaccess mydb = new dbaccess();
mydb.sqlstr = "select count(bookid) as totalid from szhotline where bkcity=" + bkcity + " and atype=" + atype;
dataset dstotal = mydb.readtable("szhotline");
int counttotal = convert.toint32(dstotal.tables["szhotline"].rows[0]["totalid"].tostring()); //总记录数
int totalpage = 0; //总页数
if (counttotal % perpage == 0)
totalpage = convert.toint16(counttotal/perpage);
else
totalpage = convert.toint16(counttotal/perpage) + 1;

int cp_n, cp_p; 
if (cur_page > 1)
cp_p = cur_page - 1;
else
cp_p = 1;

if (cur_page < totalpage)
cp_n = cur_page + 1;
else
cp_n = totalpage;

link_p.navigateurl = "szhotline.aspx?page_c=" + cp_p + "&bkcity=" + bkcity + "&atype=" + atype;
link_n.navigateurl = "szhotline.aspx?page_c=" + cp_n + "&bkcity=" + bkcity + "&atype=" + atype;
list1.datatextfield="sitename";
list1.datavaluefield="siteurl";
arraylist arr = new arraylist();
mydb.sqlstr = "select top " + perpage + " * from (select top " + perpage*convert.toint16(cur_page) + " bookid,bookname from szhotline where atype=" + atype + " and bkcity=" + bkcity + " order by bookid desc) order by bookid asc";
dataset myds = mydb.readtable("szhotline");
for (int i=0; i {
string bkname = myds.tables["szhotline"].rows["bookname"].tostring().trim();
string bkurl = "szhotdet.aspx?bookid=" + myds.tables["szhotline"].rows["bookid"].tostring().trim();
arr.add(new navigation(bkname, bkurl));
}
list1.datasource = arr;
list1.itemsaslinks = true;
list1.databind ();

activeform = list;

说明:其中dbaccess是自定义的操作数据库的类,由于数据库使用的是access。采用的分页采用了select top n * from (select * m from table order by id desc) order by id desc的方式,调整m,n两个参数分页。

文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

加支付宝好友偷能量挖...


评论(0)网络
阅读(101)喜欢(0)Asp.Net/C#/WCF