public partial class Default : System.Web.UI.Page
{
protected static string CONNECTIONSTRING = System.Configuration.ConfigurationManager.AppSettings["configer"];
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
AspNetPager1.RecordCount = 5;//一定要设计显示条数,不然就不能分页了。
GVBind();
}
}
private void GVBind()
{
ForumDataContext db = new ForumDataContext();
var q = from p in db.ForumPostInfos
select p;
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.DataSource = q.ToList();
GridView1.DataSource = pds;
GridView1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
GVBind();
}
注:AspNetPager1.PageSize 在需要在前台配置一页显示的条数