By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,704 Members | 1,475 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,704 IT Pros & Developers. It's quick & easy.

"Index Was Out of Range" Error Message from the DataGrid

P: n/a
I ran the sample application called Petstore from msdn.
Everything went fine until I tested Update button on the
web form to update the database through Datagrid.
I have been searching the web to track down this error,
but none of them really explain this problem/solution
very well.
I tried hard to debug this, but debuggin itself was
impossible.

The error message is as follows:

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

Index was out of range. Must be non-negative and less
than the size of the collection. Parameter name: index
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.ArgumentOutOfRangeException:
Index was out of range. Must be non-negative and less
than the size of the collection. Parameter name: index

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:
[ArgumentOutOfRangeException: Index was out of range.
Must be non-negative and less than the size of the
collection.
Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Web.UI.WebControls.DataKeyCollection.get_It em
(Int32 index)
Pets.PetForm.datagrid_UpdateCommand(Object source,
DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnUpdateCommand
(DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent
(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source,
EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt
(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source,
EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand
(CommandEventArgs e)

System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBa
ckEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent
(IPostBackEventHandler sourceControl, String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent
(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()

----------------------------------------------------------
------

There is an article Microsoft Knowledge Base Article -
813832, but this one mentions when ItemCommand event.
In this Pet application, Datagrid_UpdateCommand is not
even accessed due to this error.

Please somebody provide explanation and workaround for
this.
I'd appreciate sooo much.
Thank you.

Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I have a full discussion of this *bug along with a *fix at this address
http://tinyurl.com/yvqyd

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Clark Choi" <ch*******@hotmail.com> wrote in message
news:06****************************@phx.gbl...
I ran the sample application called Petstore from msdn.
Everything went fine until I tested Update button on the
web form to update the database through Datagrid.
I have been searching the web to track down this error,
but none of them really explain this problem/solution
very well.
I tried hard to debug this, but debuggin itself was
impossible.

The error message is as follows:

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

Index was out of range. Must be non-negative and less
than the size of the collection. Parameter name: index
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.ArgumentOutOfRangeException:
Index was out of range. Must be non-negative and less
than the size of the collection. Parameter name: index

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:
[ArgumentOutOfRangeException: Index was out of range.
Must be non-negative and less than the size of the
collection.
Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Web.UI.WebControls.DataKeyCollection.get_It em
(Int32 index)
Pets.PetForm.datagrid_UpdateCommand(Object source,
DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnUpdateCommand
(DataGridCommandEventArgs e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent
(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source,
EventArgs args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt
(Object source, EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source,
EventArgs args)
System.Web.UI.WebControls.LinkButton.OnCommand
(CommandEventArgs e)

System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBa
ckEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent
(IPostBackEventHandler sourceControl, String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent
(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()

----------------------------------------------------------
------

There is an article Microsoft Knowledge Base Article -
813832, but this one mentions when ItemCommand event.
In this Pet application, Datagrid_UpdateCommand is not
even accessed due to this error.

Please somebody provide explanation and workaround for
this.
I'd appreciate sooo much.
Thank you.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.