【发布时间】:2011-10-20 00:26:43
【问题描述】:
即我的页面上有一段代码如下,在page_load中
Dim subTotal As Integer = 0
For Each item As CartItem In ShoppingCart.Instance.Items
subTotal += 1
Next
strShoppingCart.Append(subTotal).Append(" Items")
shoppingCartItems.Text = strShoppingCart.ToString()
然后我可以按如下方式将商品添加到我的购物车
Protected Sub Update_Click(ByVal sender As Object, ByVal e As EventArgs) Dim rowscount As Integer = productListTable.Rows.Count
For Each row As GridViewRow In productListTable.Rows
If row.RowType = DataControlRowType.DataRow Then
' We'll use a try catch block in case something other than a number is typed in. If so, we'll just ignore it.
Try
' Get the productId from the GridView's datakeys
Dim productId = Convert.ToInt32(productListTable.DataKeys(row.RowIndex).Value)
' Find the quantity TextBox and retrieve the value
Dim quantity = Integer.Parse(CType(row.Cells(1).FindControl("txtQuantity"), TextBox).Text)
'Dim price = Decimal.Parse(CType(row.Cells(1).FindControl("TradePriceField"), Label).Text)
Dim price = Decimal.Parse("16.00")
Dim productName = CType(row.Cells(1).FindControl("ProductNameField"), Label).Text
Dim packSize = Integer.Parse(CType(row.Cells(1).FindControl("PackSizeField"), Label).Text)
Dim stockIndicator = Integer.Parse(CType(row.Cells(1).FindControl("PackSizeField"), Label).Text)
ShoppingCart.Instance.AddItem(productId, quantity, price, productName, packSize, stockIndicator)
Catch ex As FormatException
End Try
End If
Next
End Sub
问题如下
页面加载 项目数为 0
当会话中实际上有 1 个项目时,我添加了一个页面仍然显示 0 个项目的产品 我刷新了计数器转到的页面
如何读取正确的会话数?
【问题讨论】:
标签: asp.net