Hi.
Can someone pls help me with a little problem I have? I have wrote a code to add items to my shopping cart (code below). What I wish to accomplish is that if the customer adds the same item to the shopping cart twice the system adds one to the items amount in the shopping cart instead of adding a new line in the cart. Is there a simple code I can add to this code to accomplish this?
Dim row As GridViewRow
Dim isbn As String
Dim title As String
Dim amount As Integer
Dim price As Double
Dim t As TextBox
Dim p As Label
Dim totalprice As Double
row = GridView1.SelectedRow
t = CType(row.Cells(8).Controls(1), TextBox)
amount = CInt(t.Text)
p = CType(row.Cells(3).Controls(1), Label)
price = CDbl(p.Text) * amount
isbn = row.Cells(0).Text
tittel = row.Cells(1).Text
If amount = 0 Then
Server.Transfer(isbn & ".aspx")
Else
Dim shoppingcart As New Data.DataTable
shoppingcart = CType(Session("cart"), Data.DataTable)
Dim nyrow As Data.DataRow
nyrow = handlekurv.NewRow
nyrow(0) = isbn
nyrow(1) = title
nyrow(2) = amount
nyrow(3) = price
shoppingcart.Rows.Add(nyrow)
Session("cart") = shoppingcart
'regner ut totalprisen i handlekurva og skriver denne ut på siden
totalprice = Session.Item("Totalprice")
totalprice = totalprice + price
Session.Add("Totalprice", totalprice)
End If
Server.Transfer(isbn & ".aspx")
Else
Dim shoppingcart As New Data.DataTable
shoppingcart = CType(Session("cart"), Data.DataTable)
Dim nyrow As Data.DataRow
nyrow = handlekurv.NewRow
nyrow(0) = isbn
nyrow(1) = title
nyrow(2) = amount
nyrow(3) = price
-----------
datarow[] dr = shoppingCart.Select('isbn=
if dr.length = 0 then
shoppingcart.Rows.Add(nyro
else
'I am not sure but,
dr["amount"] += 1 could be enough. if it is not, find the row and increase the amount.
end if
-----
Session("cart") = shoppingcart
'regner ut totalprisen i handlekurva og skriver denne ut på siden
totalprice = Session.Item("Totalprice")
totalprice = totalprice + price
Session.Add("Totalprice", totalprice)
End If