首页 > 编程 > .NET > 正文

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

2024-07-10 12:56:14
字体:
来源:转载
供稿:网友
注册会员,创建你的web开发资料库, 

一、创建一个类
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; } }
}

二、分页
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两个参数分页。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表