您的位置:首页 > 编程语言 > ASP

DataList分页(用AspNetPager控件)

2011-09-30 14:03 148 查看
AspNetPager支持两种方式分页:

一种是PostBack方式分页,一种是通过Url来实现分页以及Url重写功能

AspNetPager支持各种数据绑定控件GridView、DataGrid、DataList、Repeater以及自定义的数据绑定控件的分页功能十分强大。

AspNetPager分页控件本身并不显示任何数据,而只显示分页导航元素,数据在页面上的显示方式与该控件无关,所以需要手写数据连接方法来配合,

结合TOP。。。NOTIN的通用存储过程分页方法使用AspNetPager十分实用

测试控件datalistaspnetpager的分页方法示例分页方法为PostBack方式

1、首先将AspNetPager.dll复制于应用程序下的bin目录,打开解决方案,引入dll文件

<%@RegisterAssembly="AspNetPager"Namespace="Wuqi.Webdiyer"TagPrefix="webdiyer"%>

2、在工具栏中添加控件,这样可以支持拖拽使用

3、要使用AspNetPager要为其设置最基本的属性

控件下载地址:

http://www.webdiyer.com/Controls/AspNetPager/Downloads

CSS:

<styletype="text/css">
.anpager.cpb{background:#4BB0DEnonerepeatscroll00;border:1pxsolid#CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px4px00;padding:4px5px0;}

.anpagera{background:#FFFFFFnonerepeatscroll00;border:1pxsolid#CCCCCC;color:#1F3A87;margin:5px4px00;padding:4px5px0;text-decoration:none}
.anpagera:hover{background:#8BD0F6nonerepeatscroll00;border:1pxsolid#1F3A87;color:#FFFFFF;}
</style>


<webdiyer:AspNetPagerWidth="99%"ID="AspNetPager1"MoreButtonType="Text"PagingButtonType="Text"
PageSize="15"AlwaysShow="false"runat="server"SubmitButtonText="Go"HorizontalAlign="Right"
ShowCustomInfoSection="Right"CustomInfoHTML="共%PageCount%页,每页%PageSize%条"
OnPageChanged="AspNetPager1_PageChanged"NextPageText="下一页"FirstPageText="首页"
LastPageText="尾页"PageIndexBoxType="TextBox"PrevPageText="上一页"ShowPageIndexBox="Always"
TextAfterPageIndexBox="页"TextBeforePageIndexBox="转到"CssClass="anpager"CurrentPageButtonClass="cpb"
CustomInfoSectionWidth="220px"Height="13px">
</webdiyer:AspNetPager>


后台主要代码:

privatevoidshow()
{
stringsplb=splbbh;
stringpszx=ddlpszx.SelectedValue;

stringstrsql="sql语句”;
DataTabledt=db.ds_sql(strsql).Tables[0];
PagedDataSourcepds=newPagedDataSource();
pds.DataSource=dt.DefaultView;
pds.AllowPaging=true;
pds.PageSize=this.AspNetPager1.PageSize;

this.AspNetPager1.RecordCount=(int)pds.DataSourceCount;
pds.CurrentPageIndex=this.AspNetPager1.CurrentPageIndex-1;
LbRecordCount.Text=pds.DataSourceCount.ToString();
dllist.DataSource=pds;
dllist.DataBind();

}
protectedvoidAspNetPager1_PageChanged(objectsender,EventArgse)
{
show();
}


效果图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息