简单实用的分页控件 AspNetPager.dll 的使用方法
前台页面的代码:
<webdiyer:AspNetPager Width="99%" urlpaging="true" urlpageindexname="page"
id="anp" morebuttontype="Text"
numericbuttontype="Text" pagingbuttontype="Image" pagesize="10" imagepath="http://www.cnblogs.com/Images/Page/"
alwaysshow="false" runat="server" showinputbox="Always" inputboxclass="Page_TextBox"
submitbuttonclass="" submitbuttontext="GO" textafterinputbox=" " horizontalalign="Right"
showcustominfosection="Left" custominfohtml="总记录数:0 总页数:0"
onpagechanged="anp_PageChanged" >
</webdiyer:AspNetPager>
后台代码:
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;
}