1.引用AspNetPager.dll插件
1.下载AspNetPager.dll插件到bin文件夹中。
2.在“引用中添加引用”(不然报错:未能在全局命名空间中找到类型或命名名空间名称“Wuqi”)
3.添加AspNetPager的命名空间:<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
2.前台代码(将控件代码放到想要的位置)
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" Width=""
UrlPaging="true" ShowPageIndexBox="Always" PageIndexBoxType="DropDownList"
TextBeforePageIndexBox="转到" HorizontalAlign="right" PageSize=""
OnPageChanged="AspNetPager1_PageChanged" EnableTheming="true"
FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页"
SubmitButtonText="Go" TextAfterPageIndexBox="页" Style="font-size: medium"
ShowBoxThreshold="">
</webdiyer:AspNetPager>
3.后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class my : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int classid = Convert.ToInt32(Request.QueryString["Classid"]);
if (!IsPostBack)
{
//首次加载,调用函数
Databind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
}
private void Databind(int classid)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ; //获取或设置数据源
AspNetPager1.RecordCount =; //分页数据原对象
pds.AllowPaging = true; //允许分页
pds.PageSize = ; //单页显示项数
pds.CurrentPageIndex =CurrentPageIndex - ; //当前页数
Repeater.DataSource = pds; //将数据绑定到repeter控件上
Repeater2.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
//页面改变时,调用函数
Databind();
}
}