Solved

Binding Gridview to Array or Datatable Cause Error: The GridView 'GridViewID' fired event PageIndexChanging which wasn't handled.

Posted on 2010-09-08
3
478 Views
Last Modified: 2012-05-10
Scenario:
I am binding a gridview to a DataTable created at run time.   As a result of not setting the DataSourceID property of the GridView to a DataSourceControl DataSource, you have to add event handlers for sorting and paging.  I get the following error when I click on the page index button at the bottom of the GridView

Error Message:
The GridView 'gvSummary' fired event PageIndexChanged which wasn't handled.

Code Snippets:

First Here is my code on the PageIndexChangedEvent.  This is where I am having a problem.  I can't get to the e.NewPageIndex  property.  When I type e. in intellesense it only exposes the following properties:   Equals, GetHasCode, GetType, ToString
The NewPageIndex property is not passed in from the sender.  What am I doing wrong

Event Handler code:
protected void gvSummary_PageIndexChanged(object sender, EventArgs e)
    {
        gvSummary.PageIndex = e.NewPageIndex;  //Does not work, NePageIndex not in list
        gvSummary.DataBind();
    }
Code for Creation of DataTable at runtime:

   //Create Columns in Datatable
        DataTable SummaryTable = new DataTable();
        SummaryTable.Columns.Add("GroupNo");
        SummaryTable.Columns.Add("GroupDesc");
        SummaryTable.Columns.Add("Code");
        SummaryTable.Columns.Add("Description");

        DataRow sumRow = SummaryTable.NewRow();

        //Get Values for Current row.
        Circuit = af.ReturnSummaryItems(GroupNo, frameID, Code);

        sumRow["PoleNo"] = poleNo;
        sumRow["GroupNo"] = GroupNo;
        sumRow["GroupDesc"] = Circuit.GroupDesc;
        sumRow["Code"] = Code;
        sumRow["Description"] = Circuit.Description;

        SummaryTable.Rows.Add(sumRow);
        SummaryTable.AcceptChanges();

        gvSummary.DataSource = SummaryTable;
        gvSummary.DataBind();

Gridview HTML Code:

<asp:GridView ID="gvSummary" runat="server" AutoGenerateColumns="False" BackColor="White"
            BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" Font-Names="Arial"
            Font-Size="X-Small" GridLines="Vertical" Font-Bold="False" AllowPaging="True" OnPageIndexChanged="gvSummary_PageIndexChanged" PageSize="21">
            <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
            <Columns>
                <asp:BoundField DataField="PoleNo" HeaderText="Pole" />
                <asp:BoundField DataField="GroupNo" HeaderText="GroupNo" />
                <asp:BoundField DataField="GroupDesc" HeaderText="GroupDesc" />
                <asp:BoundField DataField="Code" HeaderText="Code" />
                <asp:BoundField DataField="Description" HeaderText="Code Desc" />
            </Columns>
            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="Gainsboro" />
        </asp:GridView>
0
Comment
Question by:jholmes0724
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Kaushal Arora earned 500 total points
Comment Utility
The error is because you have handled the PageIndexChanged event in place of PageIndexChanging event. When ever you click the Index of the Pages it will fire the PageIndexChanging Event which you have not handled. You have to handle the PageIndexChanging event in place of PageIndexChanged event or you can just replace it.
0
 
LVL 12

Expert Comment

by:Kaushal Arora
Comment Utility
The PageIndexChanged event will get fired after the index have been changed.
0
 

Author Closing Comment

by:jholmes0724
Comment Utility
Thank you, yes that makes total sense.  
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now