private void bind() {
AspNetPager1.RecordCount = getCount();
AspNetPager1.PageSize = 5;
string sql = "select * from Books";
SqlDataAdapter da = new SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
DataTable dt = new DataTable();
da.Fill((AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize, AspNetPager1.PageSize, dt);
Repeater1.DataSource = dt.DefaultView;
Repeater1.DataBind();
}
private int getCount() {
string sql = "select count(*) from Books";
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString))
{
SqlCommand cmd = new SqlCommand(sql,conn);
conn.Open();
int num = Convert.ToInt32(cmd.ExecuteScalar());
conn.Close();
return num;
}
}
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.CurrentPageIndex = e.NewPageIndex;
bind();
}
<webdiyer:AspNetPager ID="AspNetPager1" runat="server"
FirstPageText="首页" LastPageText="末页" NextPageText="下一页" NumericButtonCount="5"
onpagechanging="AspNetPager1_PageChanging" PageIndexBoxType="DropDownList"
PageSize="5" PrevPageText="上一页" ShowCustomInfoSection="Left"
ShowPageIndexBox="Always" >
</webdiyer:AspNetPager>