asp.net GridView触发了未处理的事件PageIndexChanging

nbnkbykc  于 12个月前  发布在  .NET
关注(0)|答案(6)|浏览(125)

我已经允许分页并添加了下面的代码,但得到了错误。有人知道可能是什么问题吗?
代码:

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>

62lalag4

62lalag41#

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

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

<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

hkmswyz6

hkmswyz62#

您的代码应该在OnPageIndexChanging事件中

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>

k10s72fa

k10s72fa3#

尝试

OnPageIndexChanging="SubmitAppraisalGrid_PageIndexChanging"

字符串
而不是

onselectedindexchanging="SubmitAppraisalGrid_SelectedIndexChanging"

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

j91ykkif

j91ykkif4#

代替使用

SubmitAppraisalGrid.PageIndex = e.NewSelectedIndex;

字符串
您必须使用

SubmitAppraisalGrid.PageIndex = e.NewPageIndex;


如果你再次出错,请把错误也贴出来。

flvtvl50

flvtvl505#

一步一步:
1.从design中选择gridview,然后转到property并触发事件(PageIndexChanging)
1.产品编号:gridviewname.pageindex=e.NewPageIndex;

fxnxkyjh

fxnxkyjh6#

您需要从已选择的索引更改事件中调用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);
}

字符串

相关问题