The GridView fired event PageIndexChanging which wasn't handled
Asked Answered
C

6

13

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>
Clinquant answered 16/3, 2012 at 3:56 Comment(0)
E
13

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

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

<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 PageIndex property. Check MSDN documentation of GridView.PageIndexChanging Event

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

Eventual answered 16/3, 2012 at 4:55 Comment(1)
+1 for letting us know about AllowPaging attribute. If this is is set to "true" can also cause the issue without the PageIndexChanging event.Foundling
L
11

Your code should be inside On PageIndexChanging Event

  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>
Leibniz answered 25/6, 2014 at 18:59 Comment(0)
R
3

try

OnPageIndexChanging="SubmitAppraisalGrid_PageIndexChanging"

instead of

onselectedindexchanging="SubmitAppraisalGrid_SelectedIndexChanging"


protected void SubmitAppraisalGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    SubmitAppraisalGrid.PageIndex = e.NewPageIndex;
    BindGrid();
}
Rounce answered 16/3, 2012 at 4:6 Comment(0)
G
0

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

Gpo answered 16/3, 2012 at 4:20 Comment(0)
K
0

Step by Step:

  1. Select gridview from design and go to property and fire the event (PageIndexChanging)
  2. Code : gridviewname.pageindex=e.NewPageIndex;
Kulak answered 9/11, 2012 at 7:23 Comment(1)
Please read other answers. Yours doesn't seem to add something new to them.Analgesia
P
0

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

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);
}
Plummy answered 26/12, 2014 at 12:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.