下面所记得东西仅仅是使用方法,详细知识点请看链接:http://www.webdiyer.com/Controls/AspNetPager/Downloads
首先:从网站上下载并安装控件
下载地址: http://www.nuget.org/packages/AspNetPager_CN/(若无法打开,直接在Nuget中输入以下命令进行安装)
PM> Install-Package AspNetPager_CN
将控件拖进web窗体中,设置如下格式
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" UrlPaging="true" AlwaysShow="true"
FirstPageText="首页" LastPageText="末页" OnPageChanged="AspNetPager1_PageChanged"
NextPageText="下一页" PrevPageText="上一页" CustomInfoHTML="目前是第%CurrentPageIndex%页 / 总共%PageCount%页"
ShowCustomInfoSection="Right" PagingButtonSpacing="0px" NumericButtonCount="5"
CssClass="anpager" CurrentPageButtonClass="cpb" Width="850px">
</webdiyer:AspNetPager>
样式如下:
后台代码
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindRepeater();
}
} private void BindRepeater()
{
int currentPage = AspNetPager1.CurrentPageIndex;
int pageSize = AspNetPager1.PageSize;
int recordCount; StudentDAL dal = new StudentDAL();
DataSet ds = dal.GetPage(currentPage, pageSize, out recordCount);
AspNetPager1.RecordCount = recordCount;
string ss = AspNetPager1.CustomInfoHTML;
//AspNetPager1.CustomInfoHTML += "共" + recordCount + "条新闻"; Repeater1.DataSource = ds;
Repeater1.DataBind(); } protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
BindRepeater();
}
DAL层代码
/// <summary>
/// 得到数据页
/// </summary>
/// <param name="currentPage">当前第几页</param>
/// <param name="pageSize">每页有多少条数据</param>
/// <param name="recordCount">数据总条数</param>
/// <returns></returns>
public DataSet GetPage(int currentPage, int pageSize, out int recordCount)
{
int start=;
if(currentPage<=)
{
}
else
{
start=(currentPage-)*pageSize;
} int end=currentPage*pageSize;
string sql = "select top "+pageSize+" * from T_Student where Id not in(select top "+start+" Id from T_Student)"; //SqlParameter[] ps = {
// new SqlParameter("@takeNum",pageSize),
// new SqlParameter("@skipNum",start)
// };
recordCount = (int)SqlHelper.ExecuteScalar("select count(1) from T_Student");
return SqlHelper.ExecuteDatable(CommandType.Text, sql);
}
同样可以设置控件css样式:
CSS样式:
/*先引入bootstrap.css*/
.pagination a[disabled]{ color: #777;cursor: not-allowed;background-color: #fff;border-color: #ddd;}
.pagination span.active{z-index: 2;color: #fff;cursor: default;background-color: #337ab7;border-color: #337ab7;}
属性设置:CssClass="pagination" LayoutType="Ul" PagingButtonLayoutType="UnorderedList" PagingButtonSpacing="0" CurrentPageButtonClass="active"
网易风格:
CSS样式:
.anpager .cpb {background:#1F3A87 none repeat scroll 0 0;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px 4px 0 0;padding:4px 5px 0;}
.anpager a {background:#FFFFFF none repeat scroll 0 0;border:1px solid #CCCCCC;color:#1F3A87;margin:5px 4px 0 0;padding:4px 5px 0;text-decoration:none}
.anpager a:hover{background:#1F3A87 none repeat scroll 0 0;border:1px solid #1F3A87;color:#FFFFFF;}
属性设置:CssClass="anpager" CurrentPageButtonClass="cpb" PagingButtonSpacing="0"
拍拍网风格:
CSS样式:
.paginator { font: 11px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}
.paginator a {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px}
.paginator a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
.paginator .cpb {padding: 1px 6px;font-weight: bold; font-size: 13px;border:none}
.paginator a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;}
属性设置:CssClass="paginator" CurrentPageButtonClass="cpb" PagingButtonSpacing="0"
迅雷风格:
CSS样式:
.pages { color: #999;overflow: auto; }
.pages a, .pages .cpb { text-decoration:none;float: left; padding: 0 5px; border: 1px solid #ddd;background: #ffff;margin:0 2px; font-size:11px; color:#000;}
.pages a:hover { background-color: #E61636; color:#fff;border:1px solid #E61636; text-decoration:none;}
.pages .cpb { font-weight: bold; color: #fff; background: #E61636; border:1px solid #E61636;}
属性设置:CssClass="pages" CurrentPageButtonClass="cpb" PagingButtonSpacing="0"