Hi All
I have a shoppingcart.aspx web form that use coding same as source in IBUYSPY( sample from
www.asp.net) and use Oracle92 for its database.For the selection productID to Cart,it works fine but if i click the update button.It shows error like this.
***************************
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
***************************
And It highlights on this line.
If quantity <> CInt(DataGrid1.DataKeys(i)) Or remove.Checked = True Then
***************************
And this is my code.
Sub UpdateShoppingCartDatabase()
Dim cart As VCDeasy.ShoppingCartDB = New VCDeasy.ShoppingCartDB
' Obtain current user's shopping cart ID
Dim cartId As String = cart.GetShoppingCartId()
' Iterate through all rows within shopping cart list
Dim i As Integer
For i = 0 To DataGrid1.Items.Count - 1
' Obtain references to row's controls
Dim quantityTxt As TextBox = CType(DataGrid1.Items(i).FindControl("Quantity"), TextBox)
Dim remove As CheckBox = CType(DataGrid1.Items(i).FindControl("CheckBox1"), CheckBox)
' Wrap in try/catch block to catch errors in the event that someone types in
' an invalid value for quantity
Dim quantity As Integer
quantity = CInt(quantityTxt.Text)
' If the quantity field is changed or delete is checked
If quantity <> CInt(DataGrid1.DataKeys(i)) Or remove.Checked = True Then
Dim lblProductID As Label = CType(DataGrid1.Items(i).FindControl("ProductID"), Label)
If quantity = 0 Or remove.Checked = True Then
cart.RemoveItem(cartId, CInt(lblProductID.Text))
Else
cart.UpdateItem(cartId, CInt(lblProductID.Text), quantity)
End If
End If
Next
End Sub
**********************************
I think the problem come from i - parameter but not understand for this point.
How i can solve this problem?
Thanks in advance
Blueman137