欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

asp.net repeater手写分页实例代码

程序员文章站 2024-03-09 14:18:59
复制代码 代码如下:using system; using system.collections.generic; using system.linq; using sys...
复制代码 代码如下:

using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using bll;
using model;
using system.data.sqlclient;
using system.data;
public partial class test_repeaterfenye : system.web.ui.page
{
private readonly static categorybll cb = new categorybll();
private readonly static category_info cgi = new category_info();
int menu_id = 0;
protected void page_load(object sender, eventargs e)
{
if (!ispostback)
{
binddata();
}
}
private void binddata()
{
ilist<category_info> li = cb.getallcategory();
if (li.count > 0)
{
pageddatasource pds = new pageddatasource();
pds.datasource = li;
pds.allowpaging = true;
pds.pagesize =2;
int curpage;
if (request.querystring["page"] != null)
{
curpage = convert.toint32(request.querystring["page"]);
}
else
{
curpage = 1;
}
pds.currentpageindex = curpage - 1;
this.repeater1.datasource = pds;
this.repeater1.databind();
this.label4.text = "";
this.label4.text += "<a>共有<font color=red><b>" + li.count.tostring() + "</b></font>条记录</a> ";
this.label4.text += "<a>每页显示<font color=red><b>" + pds.pagesize + "</b></font>条</a> ";
this.label4.text += "<a>共<font color=red><b>" + pds.pagecount.tostring() + "</b></font>页</a> ";
this.label4.text += "<a>当前第<font color=red><b>" + curpage.tostring() + "</b></font>页</a>  ";
if (curpage == 1)
{
this.label4.text += "<a>首页</a> ";
this.label4.text += "<a>上一页</a> ";
}
else
{
//this.label4.text += "<a href='wjproduct-1-" + menu_id + ".html'>首页</a> ";
//this.label4.text += "<a href='wjproduct-" + (curpage - 1).tostring() + "-" + menu_id + ".html'>上一页</a>  ";
this.label4.text += "<a href='repeaterfenye.aspx'>首页</a> ";
this.label4.text += "<a href='repeaterfenye.aspx?page="+(curpage - 1).tostring()+"'>上一页</a>  ";
}
if (curpage == pds.pagecount)
{
this.label4.text += "<a>下一页</a> ";
this.label4.text += "<a>尾页</a> ";
}
else
{
this.label4.text += "<a href='repeaterfenye.aspx?page=" + (curpage + 1).tostring() + "'>下一页</a>  ";
this.label4.text += "<a href='repeaterfenye.aspx?page=" + pds.pagecount.tostring() + "'>尾页</a>  ";
//this.label4.text += "<a href='wjproduct-" + (curpage + 1).tostring() + "-" + menu_id + ".html'>下一页</a> ";
//this.label4.text += "<a href='wjproduct-" + pds.pagecount.tostring() + "-" + menu_id + ".html'>尾页</a> ";
}
string htmlselectstring = "<select onchange=\"javascript:window.location=this.value\">";
for (int i = 1; i <= pds.pagecount; i++)
{
if (i == curpage)
{
//htmlselectstring += "<option value=wjproduct-" + i + "-" + menu_id + ".html selected>第" + i + "页</option>";
htmlselectstring += "<option value='repeaterfenye.aspx?page=" + i.tostring() +"' selected>第" + i + "页</option>";
}
else
{
//htmlselectstring += "<option value=wjproduct-" + i + "-" + menu_id + ".html>第" + i + "页</option>";
htmlselectstring += "<option value='repeaterfenye.aspx?page=" + i.tostring() + "'>第" + i + "页</option>";
}
}
htmlselectstring += "</select>";
this.label4.text += "<a>" + htmlselectstring + "</a>";
}
else
{
label4.text = "没有数据!";
}
}
}
注://注释部分为url rewrite的效果。。。li返回的值为sql查询后所得到表中所有的记录。。。