我正在尝试使用GridView进行分页,
我已经添加了GridView的PageIndexChanging方法,
但第二页返回一个空页。
我对这段代码做错了什么?
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
答案 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();
}