>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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only