C# GridView 触发了未处理的事件 PageIndexChanging

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9731645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 08:37:14  来源:igfitidea点击:

The GridView fired event PageIndexChanging which wasn't handled

c#asp.netvisual-studio-2010page-index-changed

提问by

i have allowed paging and added the below codes but got the error. Does anyone know what could be the problem?

我已经允许分页并添加了以下代码,但出现错误。有谁知道可能是什么问题?

Code:

代码:

  protected void SubmitAppraisalGrid_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        SubmitAppraisalGrid.PageIndex = e.NewSelectedIndex;
        SubmitAppraisalGrid.DataBind();

    }

Design:

设计:

<asp:GridView ID="SubmitAppraisalGrid" runat="server" 
                AutoGenerateColumns="False" BorderWidth="0px" 
                onrowcreated="SubmitAppraisalGrid_RowCreated" ShowHeader="False" 
                style="margin-right: 0px" AllowPaging="True" PageSize="1" 
                onselectedindexchanging="SubmitAppraisalGrid_SelectedIndexChanging">
               </asp:GridView>

回答by Darshana

try

尝试

OnPageIndexChanging="SubmitAppraisalGrid_PageIndexChanging"

instead of

代替

onselectedindexchanging="SubmitAppraisalGrid_SelectedIndexChanging"


protected void SubmitAppraisalGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
    BindGrid();
}

回答by Ajay Mirge

insted of using

开始使用

SubmitAppraisalGrid.PageIndex = e.NewSelectedIndex;

you must use

你必须使用

SubmitAppraisalGrid.PageIndex = e.NewPageIndex;

and if you got error again plese post the error too..

如果您再次出现错误,请也发布错误..

回答by Niranjan Singh

If you have set a gridviews AllowPaging attribute to “true” and do not handle the PageIndexChangingevent then this error raise.

如果您已将 gridviews AllowPaging 属性设置为“true”并且不处理该PageIndexChanging事件,则会引发此错误。

To work with paging add the PageIndexChangingevent handler to grid and change your markup and code as:

要使用分页,请将PageIndexChanging事件处理程序添加到网格并将您的标记和代码更改为:

<asp:GridView ID="SubmitAppraisalGrid" runat="server" 
                AutoGenerateColumns="False" BorderWidth="0px" 
                onrowcreated="SubmitAppraisalGrid_RowCreated" ShowHeader="False" 
                style="margin-right: 0px" AllowPaging="True" PageSize="1" 
                onselectedindexchanging="SubmitAppraisalGrid_SelectedIndexChanging"
                OnPageIndexChanging="SubmitAppraisalGrid_PageIndexChanging">
               </asp:GridView>

///

///

protected void gvList_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
    SubmitAppraisalGrid.DataBind();

    //bindGrid(); 
    //SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
    //SubmitAppraisalGrid.DataBind();
}

protected void SubmitAppraisalGrid_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
   /// you selected index related logic here.
}

This event is not raised when you programmatically set the PageIndexproperty. Check MSDN documentation of GridView.PageIndexChanging Event

以编程方式设置PageIndex属性时不会引发此事件。检查GridView.PageIndexChanging 事件的MSDN 文档

For reference: The GridView fired event PageIndexChanging which wasn't handled

供参考: 未处理的 GridView 触发事件 PageIndexChanging

回答by Arjun Walmiki

Step by Step:

一步步:

  1. Select gridview from design and go to property and fire the event (PageIndexChanging)
  2. Code : gridviewname.pageindex=e.NewPageIndex;
  1. 从设计中选择 gridview 并转到属性并触发事件(PageIndexChanging)
  2. 代码 : gridviewname.pageindex=e.NewPageIndex;

回答by Arash

Your code should be inside On PageIndexChanging Event

您的代码应该在 On PageIndexChanging 事件中

  protected void SubmitAppraisalGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
        SubmitAppraisalGrid.DataBind();
    }

Design:

设计:

<asp:GridView ID="SubmitAppraisalGrid" runat="server" 
            AutoGenerateColumns="False" BorderWidth="0px" 
            onrowcreated="SubmitAppraisalGrid_RowCreated" ShowHeader="False" 
            style="margin-right: 0px" AllowPaging="True" PageSize="1" 
            OnPageIndexChanging="SubmitAppraisalGrid_PageIndexChanging">
           </asp:GridView>

回答by user2247929

You need to call the Pageindex changing event from selected index changing event of dropdown.

您需要从下拉列表的选定索引更改事件中调用 Pageindex 更改事件。

protected void PageDropDownList_SelectedIndexChanged(Object sender, EventArgs e)
{
     // Retrieve the pager row.
    GridViewRow pagerRow = SubmitAppraisalGrid.BottomPagerRow;

    // Retrieve the PageDropDownList DropDownList from the bottom pager row.
    DropDownList pageList = (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");

    // Set the PageIndex property to display that page selected by the user.
    GridViewPageEventArgs evt = new GridViewPageEventArgs(pageList.SelectedIndex);
    SubmitAppraisalGrid_PageIndexChanging(sender, evt);
}