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:

I think datatype conversion problem.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.