GridView1 分页 激发了未处理的事件“PageIndexChanging
这个问题已经无奈了.第一页是没有问题的.但是我只要点其他页,就会出现Message: GridView“GridView1”激发了未处理的事件“PageIndexChanging”。的错误.我检查了.已经捆绑这个事件了.并在pageindexchanging的事件里按照所有可能的捆绑数据了.但错误不改.我的页面只是继承了basepage而已.不知道会是那里有错误.
------解决方案-------------------- 如果要翻页是要写代码的 以下代码或许对你有点帮助
protected void GridView1_PageIndexChanging1(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = “数据源”;
GridView1.DataBind();
}
------解决方案--------------------如果楼主是用的VS自带的分页功能,楼上是正解
------解决方案-------------------- protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = "Data Source=(local);Database=;Uid=sa;Pwd=";
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand();
sqlcom.Connection = sqlcon;
sqlcom.CommandText = "select * from ";
SqlDataAdapter myda = new SqlDataAdapter();
myda.SelectCommand = sqlcom;
DataSet myds = new DataSet();
try
{
myda.Fill(myds, " ");
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlcon.Close();
}
if (e.NewPageIndex < 0)
{
e.NewPageIndex = 0;
}
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = myds.Tables[" "];
GridView1.DataBind();
}
再绑定一次
------解决方案--------------------页面跳转是需要重新绑定的
------解决方案--------------------protected void GridView1_PageIndexChanging1(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = “数据源”;
GridView1.DataBind();
}