Dim
Dim P As Decimal
Dim objDT As System.Data.DataTable
Dim objDR As System.Data.DataRow
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
makeCart()
End If
End Sub
Function makeCart()
objDT = New System.Data.DataTable("Cart")
objDT.Columns.Add("ID", GetType(Integer))
objDT.Columns("ID").AutoIncrement = True
objDT.Columns("ID").AutoIncrementSeed = 1
objDT.Columns.Add("Quantity", GetType(Integer))
objDT.Columns.Add("Product", GetType(String))
objDT.Columns.Add("Cost", GetType(Decimal))
objDT.Columns.Add("CodBarras", GetType(String))
Session("Cart") = objDT
End Function
Protected Sub AddToCart(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
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
Next
If Not blnMatch Then
objDR = objDT.NewRow
objDR("Quantity") = txtQuantity.Text
objDR("Product") = ddlProducts.SelectedItem.Text
objDR("Cost") = Decimal.Parse(ddlProducts.SelectedItem.Value)
objDR("CodBarras") = codbarras
objDT.Rows.Add(objDR)
dg.DataSource = objDT
dg.DataBind()
lblTotal.Text = "$" & GetItemTotal()
Function GetItemTotal() As Decimal
Dim intCounter As Integer
Dim decRunningTotal As Decimal
For intCounter = 0 To objDT.Rows.Count - 1
objDR = objDT.Rows(intCounter)
decRunningTotal += (objDR("Cost") * objDR("Quantity"))
Return decRunningTotal
Sub Delete_Item(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
objDT.Rows(e.Item.ItemIndex).Delete()
lblTotal.Text = "$" & GetItemTotal()I can add items to the gridview ant it works OK, but if I navegate to anotherpage the item disappear.I would like to add items to the gridview from another pages.I hope you understand my message. Thank you.