我的ASP.NET WebForm中有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.

提前致谢

有帮助吗?

解决方案

你必须处理 PageIndexchanging 事件,如果您单击设计人员的网格并查看事件,请双击PageIndexChanging事件,如果您不需要取消或做任何特别的事情,请重新启动处理程序中的数据

其他提示

您应该添加名称空间

使用System.Collections.generic;

并仅编写此代码

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

它100%的工作尝试...

您必须为PageIndexChanging提供活动处理程序,这是您提供分页逻辑的地方。

这样写 GridView1_PageIndexChanging 事件:

GridView1.PageIndex = e.NewPageIndex;

然后再次绑定网格。您的概率将解决。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top