The GridView fired event PageIndexChanging which wasn't handled

I am trying to implement paging on my gridview and I am getting the above error.  I must not have something set right but I can't figure out what it is.  I am reading my data into a DataTable and setting the GridView's DataSource to my datatable.  I have a PageIndexChanging method for my gridview but it is not executing the code in the method. Here is what I have.  Any help is appreciated!

GridView Markup
            <asp:GridView ID="gvOpenTeams" runat="server" CellPadding="5" 
                AlternatingRowStyle-BackColor="#0099CC" AlternatingRowStyle-BorderColor="Black" 
                AlternatingRowStyle-BorderStyle="Solid" AlternatingRowStyle-ForeColor="White" 
                AlternatingRowStyle-HorizontalAlign="Left" AlternatingRowStyle-VerticalAlign="Middle" 
                BorderStyle="Solid" HeaderStyle-BackColor="Silver" BorderColor="Black" 
                HeaderStyle-BorderColor="Black" HeaderStyle-BorderStyle="Solid" 
                HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle" 
                HorizontalAlign="Left" RowStyle-BorderColor="Black" RowStyle-BorderStyle="Solid" 
                RowStyle-HorizontalAlign="Left" RowStyle-VerticalAlign="Middle" 
                AutoGenerateColumns="false" AutoGenerateDeleteButton="false" 
                AutoGenerateEditButton="true" ShowFooter="false"
                EmptyDataText="No Open Teams Found" [b]AllowPaging="True" PageSize="10">
[/b]                <AlternatingRowStyle HorizontalAlign="Left" VerticalAlign="Middle" BackColor="#0099CC" BorderColor="Black" 
                    BorderStyle="Solid" ForeColor="White"></AlternatingRowStyle>
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" BackColor="Silver" BorderColor="Black" 
                    BorderStyle="Solid"></HeaderStyle>
                <RowStyle HorizontalAlign="Left" VerticalAlign="Middle" BorderColor="Black" BorderStyle="Solid"></RowStyle>
                <Columns>
                    <asp:BoundField DataField="OpenTeamID" HeaderText="ID" ReadOnly="true" />
                    <asp:BoundField DataField="TeamName" HeaderText="Team Name" ReadOnly="true" />
                    <asp:BoundField DataField="Manager" HeaderText="Manager" ReadOnly="true" />
                    <asp:BoundField DataField="ApprovalSup" HeaderText="Approval Supervisor" ReadOnly="true" />
                    <asp:BoundField DataField="ActiveStatusFlag" HeaderText="Active" />
                </Columns>
            </asp:GridView>

Open in new window


Code Behind
static DataTable dtOpenTeams;
protected void Page_Load(object sender, EventArgs e)
{
    --- Only relevant code is shown ---
                if (Page.IsPostBack == false)
                {
                    // Get Open Teams
                    dtOpenTeams = EMPData.GetOpenTeams();
                    if (dtOpenTeams == null)
                    {
                        Master.showResults = true;
                        Master.resultsMessage = EMPData.ErrorMessage;
                        return;
                    }

                    // Bind Open Teams to gridview
                    gvOpenTeams.DataSource = dtOpenTeams;
                    gvOpenTeams.DataBind();
                }

}

        protected void gvOpenTeams_PageIndexChanging(Object sender, GridViewPageEventArgs e)
        {
            Master.showResults = false;

            // Cancel the paging operation if the user attempts to navigate to another page while the 
            // gridview control is in edit mode.
            if (gvOpenTeams.EditIndex != -1)
            {
                // Use the Cancel property to cancel the paging operation
                e.Cancel = true;

                // Display an error message
                int newPageNumber = e.NewPageIndex + 1;
                Master.resultsMessage = "Please update the record before moving to page " + newPageNumber.ToString();
                Master.showResults = true;
            }
            else
            {
                gvOpenTeams.DataSource = dtOpenTeams;
                gvOpenTeams.PageIndex = e.NewPageIndex;
                gvOpenTeams.DataBind();
            }
        }

Open in new window

dyaroshAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jerry MillerCommented:
You need to add gvOpenTeams_PageIndexChanging to the gridview declaration:

<asp:GridView ID="gvOpenTeams" runat="server" CellPadding="5"
OnPageIndexChanged = "gvOpenTeams_PageIndexChanging "
                AlternatingRowStyle-BackColor="#0099CC" AlternatingRowStyle-BorderColor="Black"
                AlternatingRowStyle-BorderStyle="Solid" AlternatingRowStyle-ForeColor="White"
                AlternatingRowStyle-HorizontalAlign="Left" AlternatingRowStyle-VerticalAlign="Middle"
                BorderStyle="Solid" HeaderStyle-BackColor="Silver" BorderColor="Black"
                HeaderStyle-BorderColor="Black" HeaderStyle-BorderStyle="Solid"
                HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Middle"
                HorizontalAlign="Left" RowStyle-BorderColor="Black" RowStyle-BorderStyle="Solid"
                RowStyle-HorizontalAlign="Left" RowStyle-VerticalAlign="Middle"
                AutoGenerateColumns="false" AutoGenerateDeleteButton="false"
                AutoGenerateEditButton="true" ShowFooter="false"
                EmptyDataText="No Open Teams Found" AllowPaging="True" PageSize="10">
               <AlternatingRowStyle HorizontalAlign="Left" VerticalAlign="Middle" BackColor="#0099CC" BorderColor="Black"
                    BorderStyle="Solid" ForeColor="White"></AlternatingRowStyle>
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" BackColor="Silver" BorderColor="Black"
                    BorderStyle="Solid"></HeaderStyle>
                <RowStyle HorizontalAlign="Left" VerticalAlign="Middle" BorderColor="Black" BorderStyle="Solid"></RowStyle>
                <Columns>
                    <asp:BoundField DataField="OpenTeamID" HeaderText="ID" ReadOnly="true" />
                    <asp:BoundField DataField="TeamName" HeaderText="Team Name" ReadOnly="true" />
                    <asp:BoundField DataField="Manager" HeaderText="Manager" ReadOnly="true" />
                    <asp:BoundField DataField="ApprovalSup" HeaderText="Approval Supervisor" ReadOnly="true" />
                    <asp:BoundField DataField="ActiveStatusFlag" HeaderText="Active" />
                </Columns>
            </asp:GridView>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dyaroshAuthor Commented:
Used OnPageIndexChanging= "gvOpenTeams_PageIndexChanging "
in the gridview and now everything works.  Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.