摘要:AspNetPager直接結合SqlDataSource來呈現分頁
protected void Page_Load(object sender, EventArgs e)
{
bindData();
}
protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
AspNetPager1.RecordCount = e.AffectedRows;
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
bindData();
}
void bindData()
{
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
pds.DataSource = dv;
GridView1.DataSource = pds;
GridView1.DataBind();
}