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

C

Clark Choi

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_Item
(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.OnBubbleEvent
(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.
 
A

Alvin Bruney

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 said:
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_Item
(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.OnBubbleEvent
(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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top