官方例子:
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RefreshViewer(0);
}
}
protected void GridView1_PageIndexChanging(
object sender, GridViewPageEventArgs e)
{
RefreshViewer(e.NewPageIndex);
}
private void RefreshViewer(int NewIndex)
{
IPagedSelector ps = DbEntry
.From<SampleData>()
.Where(WhereCondition.EmptyCondition)
.OrderBy((DESC)"Id")
.PageSize(GridView1.PageSize)
.GetPagedSelector();
GridView1.PageIndex = NewIndex;
GridView1.DataSource = new PagedCollection(ps, NewIndex);
GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
RefreshViewer(0);
}
}
protected void GridView1_PageIndexChanging(
object sender, GridViewPageEventArgs e)
{
RefreshViewer(e.NewPageIndex);
}
private void RefreshViewer(int NewIndex)
{
IPagedSelector ps = DbEntry
.From<SampleData>()
.Where(WhereCondition.EmptyCondition)
.OrderBy((DESC)"Id")
.PageSize(GridView1.PageSize)
.GetPagedSelector();
GridView1.PageIndex = NewIndex;
GridView1.DataSource = new PagedCollection(ps, NewIndex);
GridView1.DataBind();
}
这里的GridView要设置成允许分页。
另外asp:Repeater使用方法就不能这样而要:
Code
this.rptArticleList.DataSource = ps.GetCurrentPage(2); //new PagedCollection(ps, 1);
rptArticleList.DataBind();
就是要使用GetCurrentPage函数;
this.rptArticleList.DataSource = ps.GetCurrentPage(2); //new PagedCollection(ps, 1);
rptArticleList.DataBind();