Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

GridView bound to a Datatable results in runtime error on attempts to     page.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
chike_oji@yahoo.com - 25 Jan 2008 14:31 GMT
Hello All,

Please I have a web application
in which I read an Excel spreadsheet into
a DataTable and then bind the DataTable to
a DataGridView.

Below is a summary of what I did:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (IsValid)
       {
           UploadID = Guid.NewGuid().ToString();
           string path = string.Format("{0}\\{1}.xls",
ConfigurationManager.AppSettings["ExcelFilePath"], UploadID);

           try
           {

               if (UploadExcel.PostedFile == null)
               {
                   throw new Exception("Please select a File to
upload");
               }
               UploadExcel.PostedFile.SaveAs(path);
               //Create query to be passed to the Excel conversion
method.
               string sql = "Select * from [stockdetails$]";
               //Store data from Excel file in a DataTable
               dtData =
MicrosoftExcelClient.ConvertExcelToDataTable(path, sql);
               //Bind the GridView to the DataTable to display the
data
               GridView1.DataSource = dtData;
               GridView1.DataBind();

               //Save in ViewState
               ViewState["dtData"] = dtData;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

I set AllowPaging to "true"  and anytime I execute the
web application, the first page of data is correctly displayed but
whenever I try to navaigate to the next page, it results in the
runtime error below:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Server Error in '/IConceptDBWebUpdate' Application.
--------------------------------------------------------------------------------

The GridView 'GridView1' fired event PageIndexChanging which wasn't
handled.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The GridView 'GridView1'
fired event PageIndexChanging which wasn't handled.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace
below.

Stack Trace:

[HttpException (0x80004005): The GridView 'GridView1' fired event
PageIndexChanging which wasn't handled.]

System.Web.UI.WebControls.GridView.OnPageIndexChanging(GridViewPageEventArgs
e) +1473555
  System.Web.UI.WebControls.GridView.HandlePage(Int32 newPage) +83
  System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +488
  System.Web.UI.WebControls.GridView.RaisePostBackEvent(String
eventArgument) +199

System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+174
  System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+5102

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.832;
ASP.NET Version:2.0.50727.832

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Any help with how I can achieve paging in this scenario will be
appreciated.

Thank you very much,

Regards,

Chike.
Peter Bromberg [C# MVP] - 25 Jan 2008 19:45 GMT
I'm not sure if this is really a C# language group question since it is
really about ASP.NET.
However, I'd say first of all that storing your dataasource directly in
ViewState isn't a good idea.
It "gloms up" the page with lots of content that you could store on the
server just as easily, for example is Session State.

Second, your GridView is generating the  PageIndexChanging event but
apparently you've got no code to handle it.
You might want to look that event up (or PageIndexChanged, which might be
more useful to rebind your GridView
with the new page index set) over at MSDN.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com 

> Hello All,
>
[quoted text clipped - 98 lines]
>
> Chike.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.