Aspnetpager官方介绍的主要是用于sql的例子,很多时候我们需要用到Access数据库(没有存储过程),所以必需另外探索了,在网上找了一段时候后总结如下:
1.先下载Aspnetpager.dll 文件
地址:http://www.webdiyer.com/aspnetpager/downloads/ ,然后复制到bin目录下,再在vs中添加引用
2.前台中(aspx),把控件拖到 Repeater的外面,以下是代码片断,其中很多参数可以在控件中自定义
......
</tr>
</ItemTemplate> </asp:Repeater>
</table>
<webdiyer:AspNetPager ID="AspNetPager1" runat="server"
onpagechanged="AspNetPager1_PageChanged1"
CurrentPageButtonPosition="Beginning"
CustomInfoHTML="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条" FirstPageText="首页"
LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页"
ShowCustomInfoSection="Left" ShowPageIndexBox="Always" SubmitButtonText="Go"
TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到" PageSize="10"
UrlPaging="True" AlwaysShow="True" ShowNavigationToolTip="True" >
</webdiyer:AspNetPager>
.......
3.后台中(cs)
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
OleDbConnection conn = new OleDbConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["connStr"].ConnectionString);
OleDbCommand command = conn.CreateCommand();
command.Connection = conn;
conn.Open();
command.CommandType = CommandType.Text;
OleDbDataAdapter ad = new OleDbDataAdapter(command);
command.CommandText = string.Format("SELECT count(*) FROM Art ");
AspNetPager1.RecordCount = int.Parse(command.ExecuteScalar().ToString());
command.CommandText = string.Format("SELECT * FROM Art ");
DataSet ds = new DataSet();
ad.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "Product");
conn.Close();
rptCate.DataSource = ds.Tables[0].DefaultView;
rptCate.DataBind();
}
/// <summary>
/// 查询条件
/// </summary>
protected void AspNetPager1_PageChanged1(object sender, EventArgs e)
{
BindData();
}
如果看不到图片请看:http://blog.sina.com.cn/s/blog_5c5357aa0101p134.html