0

我的asp.net 网络表单中有gridview。

我像这样将我的数据库绑定到gridview:

SQL = "SELECT id,Fname,Lname FROM MEN";
dsView = new DataSet();
adp = new SqlDataAdapter(SQL, Conn);
adp.Fill(dsView, "MEN");
adp.Dispose();
GridView1.DataSource = dsView.Tables[0].DefaultView;
GridView1.DataBind();

我把这个放在gridview中:allowPaging = true

它在网格中显示数据,但如果我按到第 2..3 页 ..

我得到了这个错误:

The GridView 'GridView1' fired event PageIndexChanging which wasn't handled. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.

提前致谢

4

4 回答 4

4

您必须处理PageIndexChanging事件,如果您单击设计器上的网格并查看事件,双击 PageIndexChanging 事件,如果您不需要取消或执行任何特殊操作,只需在处理程序中重新绑定数据

于 2011-01-19T18:19:31.903 回答
3

你应该只添加命名空间

使用 System.Collections.Generic;

只写这段代码

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

它 100% 的作品尝试它......

于 2012-10-24T08:47:03.137 回答
1

您必须为 PageIndexChanging 提供一个事件处理程序,这是您提供分页逻辑的地方。

于 2011-01-19T18:18:34.940 回答
0

GridView1_PageIndexChanging在事件中这样写:

GridView1.PageIndex = e.NewPageIndex;

然后再次绑定网格。你的问题会解决的。

于 2012-01-19T09:24:27.157 回答