【问题标题】:event PageIndexChanging wasn't handled未处理事件 PageIndexChanging
【发布时间】:2013-03-30 09:32:42
【问题描述】:

我收到“未处理的 GridView 'grdFiles' 触发事件 PageIndexChanging。”即使我添加了事件处理程序:

protected void grdFiles_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GetFiles();
        grdFiles.PageIndex = e.NewPageIndex;
        grdFiles.DataBind();

    }

有什么想法吗?

【问题讨论】:

  • 问题到底是什么?请更具体
  • @ling.s 我收到了这个错误,即使我已经处理了这个事件。问题是为什么?我该如何解决?
  • 什么错误?你提到过吗
  • @ling.s 我收到错误消息:“未处理的 GridView 'grdFiles' 触发事件 PageIndexChanging。

标签: events gridview page-index-changed


【解决方案1】:

试试这个代码。您需要在处理 PageIndexChanging 事件的代码中声明一个方法。

protected void grdFiles_PageIndexChanging (object sender, GridViewPageEventArgs  e)
{
grdFiles.PageIndex = e.NewPageIndex;
bindGridView()
}

方法bindGridView()是

private void bindGridView()
{
 grdFiles.DataSource=.....;
 grdFiles.DataBind();
}

【讨论】:

  • 这和我写的代码有什么区别?此外,我尝试重新定义数据源并在事件处理程序中重新绑定网格。没用。
  • 我已经有方法 GetFiles() 可以在第一页上很好地绑定数据。当我更改 gridView 上的页面时会出现问题。然后我得到消息说事件没有被处理(即使它应该被处理)。你的回答有什么我遗漏的吗?
  • 如果您已将 gridviews AllowPaging 属性设置为“true”
  • Alos,如果在 GridView 控件上设置 AllowPaging="true" 或 AllowSorting="true" 而不使用 DataSourceControl 数据源(即 SqlDataSource、ObjectDataSource),则会遇到这种错误跨度>
  • 感谢您的努力。该链接并没有当场解决我的问题,而是引导我找到解决方案。问题解决了,我会给你“竖起大拇指”!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-19
  • 1970-01-01
  • 2011-01-16
  • 1970-01-01
相关资源
最近更新 更多