AspNetPager.dll 分页控件使用方法、含有代码示例 [转]
下载地址:http://www.webdiyer.com/Products/AspNetPager/Downloads
AspNetPager分页示例:http://www.webdiyer.com/AspNetPagerDemo/ApplyStyles/default.aspx
下载后把控件拉进VS里就可以了,注意哦,VS2003是不可以用的!下面是代码:
protected void Pager1_PageChanged(object sender, EventArgs e)
{
OracleConnection objcon = this.getcon();
string querystr = "select * from stu";
OracleDataAdapter da = new OracleDataAdapter(querystr, objcon);
DataSet ds = new DataSet();
da.Fill(ds, "stu");
this.GridView1.DataSource = this.getPage(ds); /***主要的步骤在这里,调用下面的方法***/
this.GridView1.DataBind();
}
public PagedDataSource getPage(DataSet ds)
{
this.Pager1.RecordCount = ds.Tables[0].Rows.Count;
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.CurrentPageIndex = Pager1.CurrentPageIndex - 1;
pds.PageSize = Pager1.PageSize;
return pds;
}
你只要把代码中和数据库交互的地方换成你自己的,那就OK啦!试试吧!