当allowPaging = true时gridview出错 - asp.net

发布于 2024-10-13 00:38:15 字数 860 浏览 0 评论 0原文

我的 ASP.NET Web 表单中有 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.

提前致谢

i have gridview in my asp.net webform.

i bind my database to gridview like this:

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();

and this i put in the gridview: allowPaging = true

its show the data in the grid, but if i press to page 2..3..

and i got this error:

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.

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

稀香 2024-10-20 00:38:15

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

You have to handle the PageIndexChanging event, if you click the grid on the designer and look at the events, double click on the PageIndexChanging event, if you don't need to cancel or do anything special, just rebind the data in the handler

凉风有信 2024-10-20 00:38:15

添加命名空间

您应该只使用 System.Collections.Generic

;并编写这段代码,只有

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

它 100% 有效,尝试一下......

You Should just add the namespace

using System.Collections.Generic;

and write this code only

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

it 100% works try it......

暮光沉寂 2024-10-20 00:38:15

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

You have to provide an event handler for PageIndexChanging, which is where you provide the paging logic.

吹梦到西洲 2024-10-20 00:38:15

在 GridView1_PageIndexChanging 事件中这样写:

GridView1.PageIndex = e.NewPageIndex;

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

write like this in GridView1_PageIndexChanging event:

GridView1.PageIndex = e.NewPageIndex;

then again bind the grid.
ur prob will solve.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文