[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
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
Medium Priority
?
495 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Kaushal Arora earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

656 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