我已经允许分页并添加了下面的代码,但得到了错误。有人知道会有什么问题吗?
代码:
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>
最佳答案
如果已将gridviews allowpaging属性设置为“true”,并且未处理PageIndexChanging
事件,则会引发此错误。
要使用分页,请将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# - GridView触发了未处理的事件PageIndexChanging,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9731645/