类中代码
public static DataSet Query(string SQLString, int PageIndex, int PageSize)
{
using (SqlConnection connection = new SqlConnection(_connectionString))
{
DataSet ds = new DataSet();
try
{
connection.Open();
SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
command.Fill(ds, PageIndex, PageSize, "About");
}
catch (SqlException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}
后台代码
protected void LinkButton5_Click(object sender, EventArgs e)
{
User user = (User)Session["user"];
string userid = user.UserId.ToString();
AspNetPager2.RecordCount = DBhelp.count(userid).Rows.Count;
//表中的数据条数
DataBindlist();
}
protected void DataBindlist()
{
int pageIndex = AspNetPager2.PageSize * (AspNetPager2.CurrentPageIndex - 1);
int pageSize = AspNetPager1.PageSize;
string sql="select * from order";
DataSet ds = DBhelp.Query(sql,pageIndex, pageSize);
collect.DataSource = ds.Tables["About"];
collect.DataBind();
}
protected void AspNetPager2_PageChanging(object src, PageChangingEventArgs e)
{
AspNetPager2.CurrentPageIndex = e.NewPageIndex;
DataBindlist();
}
前台代码
<webdiyer:AspNetPager ID="AspNetPager2" runat="server" PageSize="10" FirstPageText="首页"
LastPageText="尾页" NextPageText="下一页"
PrevPageText="上一页" ShowPageIndexBox="Never" CssClass="anpager" OnPageChanging="AspNetPager2_PageChanging">
</webdiyer:AspNetPager>