GridView bound to a Datatable results in runtime error on attempts to
GridView bound to a Datatable results in runtime error on attempts to
am 28.01.2008 12:21:24 von chike_oji
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:
//////////////////////////////////////////////////////////// ///////////////=
=AD///////////////////////////////////////////////////////// ////////////////=
//=AD//////////////
if (IsValid)
{
UploadID =3D Guid.NewGuid().ToString();
string path =3D 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 =3D "Select * from [stockdetails$]";
//Store data from Excel file in a DataTable
dtData =3D
MicrosoftExcelClient.ConvertExcelToDataTable(path, sql);
//Bind the GridView to the DataTable to display the
data
GridView1.DataSource =3D dtData;
GridView1.DataBind();
//Save in ViewState
ViewState["dtData"] =3D dtData;
//////////////////////////////////////////////////////////// ///////////////=
=AD///////////////////////////////////////////////////////// ////////////////=
//=AD//////////////
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:
//////////////////////////////////////////////////////////// ///////////////=
=AD///////////////////////////////////////////////////////// ////////////////=
//=AD//////////////
Server Error in '/IConceptDBWebUpdate' Application.
------------------------------------------------------------ ---------------=
=AD-----
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(GridV iewPageEventArg=
=AD
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.IPostBackEv entHandler.Rais=
=AD
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
------------------------------------------------------------ ---------------=
=AD-----
Version Information: Microsoft .NET Framework Version:2.0.50727.832;
ASP.NET Version:2.0.50727.832
//////////////////////////////////////////////////////////// ///////////////=
=AD///////////////////////////////////////////////////////// ////////////////=
//=AD//////////////
Any help with how I can achieve paging in this scenario will be
appreciated.
Thank you very much,
Regards,
Chike.
RE: GridView bound to a Datatable results in runtime error on attempts
am 28.01.2008 20:28:05 von Manish
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(GridV iewPageEventArgÂ
> 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.IPostBackEv entHandler.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.
>
>
>
Re: GridView bound to a Datatable results in runtime error on
am 29.01.2008 10:22:32 von chike_oji
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 =3D 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=A0pm, Manish wrote:
> Hi Chike,
>
> You can page on the Grid by setting the AllowPaging property to TRUE and
> then handling the PageIndexChanging event as
>
> =A0 =A0 Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, =
ByVal
> e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles
> GridView1.PageIndexChanging
> =A0 =A0 =A0 =A0 Me.GridView1.PageIndex =3D e.NewPageIndex
> =A0 =A0 =A0 =A0 Me.GridView1.DataBind()
> =A0 =A0 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:
>
> > //////////////////////////////////////////////////////////// ////////////=
////////////////////////////////////////////////////// ////////////////=
///////=AD/=AD//////////////
> > if (IsValid)
> > =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 UploadID =3D Guid.NewGuid().ToString();
> > =A0 =A0 =A0 =A0 =A0 =A0 string path =3D string.Format("{0}\\{1}.xls",
> > ConfigurationManager.AppSettings["ExcelFilePath"], UploadID);
>
> > =A0 =A0 =A0 =A0 =A0 =A0 try
> > =A0 =A0 =A0 =A0 =A0 =A0 {
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (UploadExcel.PostedFile == null)
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 {
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 throw new Exception("Please sele=
ct a File to
> > upload");
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 UploadExcel.PostedFile.SaveAs(path);
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 //Create query to be passed to the Excel=
conversion
> > method.
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 string sql =3D "Select * from [stockdeta=
ils$]";
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 //Store data from Excel file in a DataTa=
ble
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dtData =3D
> > MicrosoftExcelClient.ConvertExcelToDataTable(path, sql);
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 //Bind the GridView to the DataTable to =
display the
> > data
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 GridView1.DataSource =3D dtData;
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 GridView1.DataBind();
>
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 //Save in ViewState
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ViewState["dtData"] =3D dtData;
> > //////////////////////////////////////////////////////////// ////////////=
////////////////////////////////////////////////////// ////////////////=
///////=AD/=AD//////////////
>
> > I set AllowPaging to "true" =A0and 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:
>
> > //////////////////////////////////////////////////////////// ////////////=
////////////////////////////////////////////////////// ////////////////=
///////=AD/=AD//////////////
> > 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(GridV iewPageEvent=
Arg
> > s
> > e) +1473555
> > =A0 =A0System.Web.UI.WebControls.GridView.HandlePage(Int32 newPage) +83
> > =A0 =A0System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e,
> > Boolean
> > causesValidation, String validationGroup) +488
> > =A0 =A0System.Web.UI.WebControls.GridView.RaisePostBackEvent(Str ing
> > eventArgument) +199
>
> > System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEv entHandler.R=
ais
> > ePostBackEvent(String
> > eventArgument) +7
> > =A0 =A0System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandl er
> > sourceControl, String eventArgument) +11
> > =A0 =A0System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
> > postData)
> > +174
> > =A0 =A0System.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
>
> > //////////////////////////////////////////////////////////// ////////////=
////////////////////////////////////////////////////// ////////////////=
///////=AD/=AD//////////////
>
> > 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 -