控件用法参考:DataList和Repeater控件的分页显示功能
数据功能实现源代码:
//对用于分页的类的引用
PagedDataSource pds=new PagedDataSource();
pds.DataSource=dt.DefaultView;//设置数据源(DataTable类型)
pds.AllowPaging=true;
//第页显示的行数
pds.PageSize=18;
//设置当前页
if(Pageindex<1) Pageindex=1;
pds.CurrentPageIndex=Pageindex-1;
rpt_NewsList.DataSource=pds;
rpt_NewsList.DataBind();
//显示页码
ltl_RecordCount.Text = pds.DataSourceCount.ToString();
ltl_PageCount.Text = pds.PageCount.ToString();
ltl_Pageindex.Text = Pageindex.ToString();
ltl_Jump.Text = Jump_List (pds.PageCount , Pageindex , L_Manage);
//显示上下翻页(URL后面跟的参数自已跟据需要定义)
lbn_First.ToolTip = "跳转到首页";
lbn_First.NavigateUrl=Request.CurrentExecutionFilePath
lbn_Prev.ToolTip = "跳转到上一页";
lbn_Prev.NavigateUrl=Request.CurrentExecutionFilePath
lbn_Next.ToolTip = "跳转到下一页";
lbn_Next.NavigateUrl=Request.CurrentExecutionFilePath
lbn_Last.ToolTip = "跳转到最后一页";
lbn_Last.NavigateUrl=Request.CurrentExecutionFilePath
//确定链接的显示方式
if(Pageindex<=1 && pds.PageCount<=1)
{
}
if(Pageindex<=1 && pds.PageCount>1)
{
}
if(Pageindex >= pds.PageCount)
{
}
/// <summary>
/// 计算分页跳转
/// </summary>
/// <param name="Pagecount">页面数</param>
/// <returns>string</returns>
private string Jump_List(int Pagecount , int Pageindex , long L_Manage)
{
StringBuilder sb = new StringBuilder ();
sb.Append ("<select id=\"Page_Jump\" name=\"Page_Jump\" onchange=\"window.location='"+ Request.CurrentExecutionFilePath
for(int i = 1 ; i <= Pagecount ; i++)
{
if(Pageindex == i)
sb.Append ("<option value='"+ i +"' selected>"+ i +"</option>");
else
sb.Append ("<option value='"+ i +"'>"+ i +"</option>");
}
sb.Append ("</select>");
return sb.ToString ();
}
动行显示效果如图:
PagedDataSource 类的部分公共属性( 略)