0

i am working on Shopping cart

in the AddToCart function
at this line >>> cost1 = Decimal.Parse(ddlProducts.SelectedItem.Value)
there is an error
this is the error message
Input string was not in a correct format.

Sub AddToCart(s As Object, e As EventArgs)
	objDT = Session("Cart")
	Dim Product = ddlProducts.SelectedItem.Text
	Dim blnMatch As Boolean = False

	For Each objDR In objDT.Rows
		If objDR("Product") = Product Then
			objDR("Quantity") += txtQuantity.Text
			blnMatch = True
			Exit For
		End If
	Next

        If Not blnMatch Then
            objDR = objDT.NewRow
            objDR("Quantity") = txtQuantity.Text
            objDR("Product") = ddlProducts.SelectedItem.Text
                 
            Dim cost1
            cost1 = Decimal.Parse(ddlProducts.SelectedItem.Value)
            MsgBox(cost1)
            objDR("Cost") = cost1
            objDT.Rows.Add(objDR)


        End If
	Session("Cart") = objDT

        dg.DataSource = objDT
	dg.DataBind()
	
        lblTotal.Text = "$" & GetItemTotal()
End Sub

need help plz :icon_sad:

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by sebastian3
0

I think datatype conversion problem.

Try this : cost1 = Decimal.Parse(Convert.ToString(ddlProducts.SelectedItem.Value)) or cost1 = Decimal.Parse(ddlProducts.SelectedItem.Text)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.