MSDOTnet.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GridView bound to a Datatable results in runtime error on at

 
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> ASPNet
Author Message
chike_oji



Joined: 13 Dec 2007
Posts: 10

PostPosted: Mon Jan 28, 2008 8:21 am    Post subject: GridView bound to a Datatable results in runtime error on at Reply with quote

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(GridViewPageEventArg­
s
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.Rais­
ePostBackEvent(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.

Archived from group: microsoft>public>dotnet>framework>aspnet
Back to top
View user's profile Send private message
Manish



Joined: 08 Aug 2007
Posts: 1

PostPosted: Mon Jan 28, 2008 4:28 pm    Post subject: RE: GridView bound to a Datatable results in runtime error o Reply with quote

Hi Chike,

You can page on the Grid by setting the AllowPaging property to TRUE and
then handling the PageIndexChanging event as

Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles
GridView1.PageIndexChanging
Me.GridView1.PageIndex = e.NewPageIndex
Me.GridView1.DataBind()
End Sub

Regards,
Manish
www.ComponentOne.com

"chike_oji@yahoo.com" wrote:

> 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(GridViewPageEventArg­
> s
> 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.Rais­
> ePostBackEvent(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.
>
>
>
Back to top
View user's profile Send private message
chike_oji



Joined: 13 Dec 2007
Posts: 10

PostPosted: Tue Jan 29, 2008 6:22 am    Post subject: Re: GridView bound to a Datatable results in runtime error o Reply with quote

Thanks a million times Manish, I am so very grateful.
Your example solved my problem. At a time I was binding to data before
the

this.GridView1.PageIndex = e.NewPageIndex

The result was that I had to click the page link twice before the
GridView
moved to the requested page. But with your suggestion, I am getting
the
right results, a click to take me to the right page.

Thank you very much.

Regards,

Chike.

On Jan 28, 8:28 pm, Manish wrote:
> Hi Chike,
>
> You can page on the Grid by setting the AllowPaging property to TRUE and
> then handling the PageIndexChanging event as
>
>     Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal
> e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles
> GridView1.PageIndexChanging
>         Me.GridView1.PageIndex = e.NewPageIndex
>         Me.GridView1.DataBind()
>     End Sub
>
> Regards,
> Manishwww.ComponentOne.com
>
>
>
> "chike_...@yahoo.com" wrote:
> > 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(GridViewPageEventArg­­
> > s
> > 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.Rais­­
> > ePostBackEvent(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.- Hide quoted text -
>
> - Show quoted text -

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Confirmation for delete command on gridview Is it possible to have a confirmation dialogue appear when the delete command is clicked on a gridview? i.e. asking the "Are you sure you wish to delete this record?" question. I just don't like the idea of someone clicking on delete by mistake and the re

Has anyone got ellipses working in a gridview or detailsview Perhaps you are familiar with the old: technique.. Well, within a gridview, if I use this technique for a field, it just sort of ignores it. If I iso

Server Error (Resources) My ASP.NET app works with resources for loading text to the different controls (multilingual app) and everything works fine. but from time to time I have the following error. Then I have to wait for some time and my app continues working (I don't have to

Get reference to control in gridview at runtime... I have a gridview control with a (and other templates). In that I have some controls (a textbox, for example, used to filter the data in the gridview). When the user clicks a button on the page (the "filter" button), I nee

NullReferenceException error on GridView rows loop Hello, I'm trying to do something in a gridview that I've previously done in a datagrid and can't figure out why it won't work here. The code will loop through the gridview properly when there is no reference to chkSelected and ProjectID but when they are
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> ASPNet All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group