Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2004, 09:37 PM
Authorized User
 
Join Date: Jan 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Error aout datagrid.datakey(i)

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








Similar Threads
Thread Thread Starter Forum Replies Last Post
DataKey / DataKeyField / DataKeyNames rsearing ASP.NET 2.0 Basics 0 June 30th, 2008 08:25 PM
DataGrid Error rsm42 ASP.NET 1.0 and 1.1 Basics 0 January 2nd, 2007 02:29 PM
DataKey error in Editable datagrid hoailing22 ASP.NET 1.0 and 1.1 Basics 2 June 10th, 2005 10:51 PM
Datagrid error lily611 General .NET 4 December 8th, 2004 10:00 AM
DataGrid Error spm74 ASP.NET 1.0 and 1.1 Basics 0 May 20th, 2004 06:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.