Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error Message
Message
From
03/05/2004 18:32:26
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
To
03/05/2004 17:58:56
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
00900533
Message ID:
00900539
Views:
17
>This is the error message and my code. Can somebody give me a hint about why I am getting this error message? Thank you in advance.
>
>ERROR MSG:***************************************
>Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
>
>CODE:***************************************

<snip>

>
> myCommand.Parameters("@cid").Value = Me.grdProducts.DataKeys(CInt(e.Item.ItemIndex))

The DataKeys collection and e.Item.ItemIndex are not always gauranteed to be synchronized. You should add a column to the grid that contains the primary key.

<snip>

> Dim NumCols As Integer = e.Item.Cells.Count
> Dim i As Integer
> For i = 4 To NumCols 'Skip first through fourth and last columns

When NumCols = e.Item.Cells.Count, e.Item.Cells will be out of range.

> Dim CurrentTextBox As System.Web.UI.WebControls.TextBox
> CurrentTextBox = e.Item.Cells(i).Controls(0)
> Dim ColValue As String = CurrentTextBox.Text
> If i < 6 And ColValue = "" Then
> Me.lblError.Text = "ERROR!!!!!"
> End If
> myCommand.Parameters(Cols(i - 1)).Value = ColValue

What is Cols in the previous line?

> Next
<snip>


There should be a source code line # in the error message that will tell you exactly where the error occurred. Which line is it occurring on?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform