关于《GridView“GridView1”激发了未处理的事件“PageIndexChanging”》的问题!
在我们使用GridView控件时,动态添加数据,不借助SqlDataSource等数据源控件时,设置了分页。
即:将GridView控件的AllowPaging属性设置为"True"时,就会出现这个错误!!
而解决的办法也非常简单,只需要添加GridView控件的 "OnPageIndexChanging" 事件!!
以下给出步骤:
1.设置GridView的AllowPaging为"True";
2.添加 "OnPageIndexChanging" 事件;
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
string query = "select * from produce_logo";
this.GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = db.dt(query);
GridView1.DataKeyNames = new string[] { "produce_logo_id" };
GridView1.DataBind();
}
{
string query = "select * from produce_logo";
this.GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = db.dt(query);
GridView1.DataKeyNames = new string[] { "produce_logo_id" };
GridView1.DataBind();
}
其中,GridView1为GridView控件!!
其实,主要还是 this.GridView1.PageIndex = e.NewPageIndex; 这一句代码的添加!!