c# – 没有处理的GridView触发事件PageIndexChanging

前端之家收集整理的这篇文章主要介绍了c# – 没有处理的GridView触发事件PageIndexChanging前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经允许分页添加了以下代码,但是收到错误.有谁知道可能是什么问题?

码:

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

    }

设计:

<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>

解决方法

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

要使用分页,将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.
}

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

以供参考:
The GridView fired event PageIndexChanging which wasn’t handled

猜你在找的C#相关文章