我已经允许分页并添加了以下代码,但得到了错误。有谁知道可能是什么问题?
代码:
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>
答案 0 :(得分:10)
如果您已将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
答案 1 :(得分:7)
将您的代码放在 PageIndexChanging事件
中 protected void SubmitAppraisalGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
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"
OnPageIndexChanging="SubmitAppraisalGrid_PageIndexChanging">
</asp:GridView>
答案 2 :(得分:2)
尝试
OnPageIndexChanging="SubmitAppraisalGrid_PageIndexChanging"
而不是
onselectedindexchanging="SubmitAppraisalGrid_SelectedIndexChanging"
protected void SubmitAppraisalGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
BindGrid();
}
答案 3 :(得分:0)
而不是使用
SubmitAppraisalGrid.PageIndex = e.NewSelectedIndex;
你必须使用
SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
如果您再次收到错误,请发布错误..
答案 4 :(得分:0)
一步一步:
gridviewname.pageindex=e.NewPageIndex;
答案 5 :(得分:0)
您需要从下拉列表的选定索引更改事件中调用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);
}