zl程序教程

您现在的位置是:首页 >  后端

当前栏目

asp.netrepeater手写分页实例代码

实例ASP代码 分页 手写 NETrepeater
2023-06-13 09:14:09 时间
复制代码代码如下:

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingBLL;
usingModel;
usingSystem.Data.SqlClient;
usingSystem.Data;
publicpartialclassTest_RepeaterFENYE:System.Web.UI.Page
{
privatereadonlystaticCategoryBLLcb=newCategoryBLL();
privatereadonlystaticCategory_Infocgi=newCategory_Info();
intMenu_ID=0;
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!IsPostBack)
{
BindData();
}
}
privatevoidBindData()
{
IList<Category_Info>li=cb.GetAllCategory();
if(li.Count>0)
{
PagedDataSourcepds=newPagedDataSource();
pds.DataSource=li;
pds.AllowPaging=true;
pds.PageSize=2;
intcurPage;
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>共有<fontcolor=red><b>"+li.Count.ToString()+"</b></font>条记录</a> ";
this.Label4.Text+="<a>每页显示<fontcolor=red><b>"+pds.PageSize+"</b></font>条</a> ";
this.Label4.Text+="<a>共<fontcolor=red><b>"+pds.PageCount.ToString()+"</b></font>页</a> ";
this.Label4.Text+="<a>当前第<fontcolor=red><b>"+curPage.ToString()+"</b></font>页</a>  ";
if(curPage==1)
{
this.Label4.Text+="<a>首页</a> ";
this.Label4.Text+="<a>上一页</a> ";
}
else
{
//this.Label4.Text+="<ahref="wjProduct-"+Menu_ID+".html">首页</a> ";
//this.Label4.Text+="<ahref=""+(curPage-1).ToString()+"-"+Menu_ID+".html">上一页</a>  ";
this.Label4.Text+="<ahref="RepeaterFENYE.aspx">首页</a> ";
this.Label4.Text+="<ahref="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+="<ahref="RepeaterFENYE.aspx?page="+(curPage+1).ToString()+"">下一页</a>  ";
this.Label4.Text+="<ahref="RepeaterFENYE.aspx?page="+pds.PageCount.ToString()+"">尾页</a>  ";
//this.Label4.Text+="<ahref=""+(curPage+1).ToString()+"-"+Menu_ID+".html">下一页</a> ";
//this.Label4.Text+="<ahref=""+pds.PageCount.ToString()+"-"+Menu_ID+".html">尾页</a> ";
}
stringHtmlSelectString="<selectonchange=\"javascript:window.location=this.value\">";
for(inti=1;i<=pds.PageCount;i++)
{
if(i==curPage)
{
//HtmlSelectString+="<optionvalue="+i+"-"+Menu_ID+".htmlselected>第"+i+"页</option>";
HtmlSelectString+="<optionvalue="RepeaterFENYE.aspx?page="+i.ToString()+""selected>第"+i+"页</option>";
}
else
{
//HtmlSelectString+="<optionvalue="+i+"-"+Menu_ID+".html>第"+i+"页</option>";
HtmlSelectString+="<optionvalue="RepeaterFENYE.aspx?page="+i.ToString()+"">第"+i+"页</option>";
}
}
HtmlSelectString+="</select>";
this.Label4.Text+="<a>"+HtmlSelectString+"</a>";
}
else
{
Label4.Text="没有数据!";
}
}
}
注://注释部分为urlrewrite的效果。。。li返回的值为SQL查询后所得到表中所有的记录。。。