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
485 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
ID: 33626353
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
ID: 33626356
The PageIndexChanged event will get fired after the index have been changed.
0
 

Author Closing Comment

by:jholmes0724
ID: 33626583
Thank you, yes that makes total sense.  
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

805 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