GridView分页无法正常工作

时间:2014-07-29 22:04:14

标签: c# asp.net gridview bind paging

我正在尝试使用GridView进行分页,
我已经添加了GridView的PageIndexChanging方法,
但第二页返回一个空页。
我对这段代码做错了什么?

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataBind();
}

2 个答案:

答案 0 :(得分:0)

当我添加此

时,此问题已解决
private void FillGrid()
{
    GridView1.DataSource = "Query..."
    GridView1.DataBind();
}

改变了:

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    FillGrid();
}

答案 1 :(得分:0)

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
       BindGrid();
    }
}
private void BindGrid()
{
    GridView1.DataSource = "Query..."
    GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender,GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    this.BindGrid();
}