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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I build my own IDE using ASP.NET MVC? 2 34
DateTimepicker 4 33
ASP.net Have sliders change in order 2 10
Reset asp.net login password 4 34
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

19 Experts available now in Live!

Get 1:1 Help Now