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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create a WebAPI using a generic return parameter 9 31
asp.net mvc5 6 21
Change to file doesn't show up 16 52
Easy filter aspnet 2 27
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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