Hi could anyone help with this one
I have description, price,and quantity on a form, by clicking an add to basket link his info should appear in a datagrid on another form but for some reason it won't load, my coding is below
Form for description, price and quantity
I'm getting object instance not set to instance of an object error, any coding/advice would be appreciated
Thanks
I have description, price,and quantity on a form, by clicking an add to basket link his info should appear in a datagrid on another form but for some reason it won't load, my coding is below
Form for description, price and quantity
VB.NET:
Private Sub lnlBasket_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnlBasket.Click
' Session variable to store item quantity
Session("Description") = Me.txtDescription.Text
' Session variable to store price
Session("Price") = Me.txtPrice.Text
' Session variable to store quantity
Session("Quantity") = Me.txtQuantity.Text
' Session variable to store item total price
Session("ItemValue") = CStr(Me.txtQuantity.Text * Me.txtPrice.Text)
'Session variable to store total order value
Session("OrderValue") = Format(Val(Session("OrderValue")) + Val(Session("ItemValue")), "##,##0.00")
If Session("dsOrderData") Is Nothing Then
Dim rowNew As DataRow = dataset1.Tables("OrderInfo").NewRow
rowNew.Item("Description") = Session("description")
rowNew.Item("Price") = Format(Val(Session("price")), "##,##0.00")
rowNew.Item("Quantity") = Val(Session("Quantity"))
rowNew.Item("Total") = Format(Val(Session("OrderValue")), "##,##0.00")
DataSet1.Tables("OrderInfo").Rows.Add(rowNew)
Session("dsOrderData") = DataSet1
Else
'Get dataset from session variable.
Dim dsOrderData As DataSet = Session("dsOrderData")
Dim rowNew As DataRow = DataSet1.Tables("OrderInfo").NewRow
rowNew.Item("Description") = Session("description")
rowNew.Item("ItemValue") = Format(Val(Session("price")), "##,##0.00")
rowNew.Item("Quantity") = Val(Session("Quantity"))
rowNew.Item("Total") = Format(Val(Session("OrderValue")), "##,##0.00")
DataSet1.Tables("OrderInfo").Rows.Add(rowNew)
Session("dsOrderData") = DataSet1
End If
Server.Transfer("shoppingbasket.aspx")
End Sub
Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Session("Clicked").ToString = "btnJam" Then
txtDescription.Text = "Jam Doughnut"
txtPrice.Text = "0.35"
ElseIf Session("clicked").ToString = "btnApple" Then
txtDescription.Text = "Apple Doughnut"
txtPrice.Text = "0.40"
ElseIf Session("Clicked").ToString = "btnChocolate" Then
txtDescription.Text = "Chocolate Doughnut"
txtPrice.Text = "0.38"
ElseIf Session("Clicked").ToString = "btnCream" Then
txtDescription.Text = "Cream Doughnut"
txtPrice.Text = "0.60"
ElseIf Session("Clicked").ToString = "btnCustard" Then
txtDescription.Text = "Custard Doughnut"
txtPrice.Text = "0.35"
ElseIf Session("Clicked").ToString = "btnJamCream" Then
txtDescription.Text = "Jam and Cream Doughnut"
txtPrice.Text = "0.75"
End If
End Sub
Shopping basket form
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dsShoppingCart As DataSet = Session("dsOrderData")
DataGrid1.DataSource = dsShoppingCart.Tables(0)
DataGrid1.DataBind()
End Sub
Thanks