how do i get purchased items to a gridview in a shopping cart?

Daniel Darko

Hey I recently created a shopping cart but I'm having problems sorting the purchased items into a gridview. this is my cart class:

Public Class Cart
    Private dt As DataTable = New DataTable()

    Public Sub New()
        dt.Columns.Add(New DataColumn("Product ID"))
        dt.Columns.Add(New DataColumn("Quantity"))
        dt.PrimaryKey = New DataColumn() {dt.Columns("Product ID")}
    End Sub

    Public Sub AddToCart(ByVal prd_id As Integer, ByVal quantity As Integer)
        Dim dr As DataRow = dt.NewRow()
        dr("Product ID") = prd_id
        dr("Quantity") = quantity
        dt.Rows.Add(dr)
    End Sub

    Public Sub RemoveFromCart(ByVal prd_id As Integer)
        Dim dr As DataRow = dt.Rows.Find(prd_id)
        dt.Rows.Remove(dr)
    End Sub

    Public Function GetCart() As DataTable
        Return dt
    End Function
End Class

This is the button function:

If Session("Customer_ID") <> Nothing Then
    Dim userCart As Cart = CType(Session("shoppingCart"), Cart)
    Dim qty As Integer = txtqty.text
    Dim pid As Integer = lblid.text
    userCart.AddToCart(pID, qty)
Else 
    Response.Redirect("User_Login.aspx")
End If

When I try to run the code I get an error saying that ("Object reference not set to an instance of an object.") please help I've completely ran out of ideas. how can i fix this?

NoAlias

The Session Key of "shoppingCart" has a value Nothing, so when you try to call the AddToCart function from your userCart instance you receive this error. You must ensure that Session("shoppingCart") is not nothing. If it is you should create it or perform the logic you wish to perform in that scenario. Note that Sessions will time out after a client is inactive for a certain amount of time (configurable in the Web.config file), so this is a very real scenario.

    Dim userCart As Cart = Nothing

    If Not Session("shoppingCart") Is Nothing Then

        userCart = CType(Session("shoppingCart"), Cart)

    Else

        userCart = New Cart

    End If

    userCart.AddToCart(pID, qty)

Don't forget to save your cart to the Session!

    Session("shoppingCart") = userCart

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How do I update my shopping cart with the product ID using an HTML form?

分類Dev

Append cart, how do I discount certain items?

分類Dev

How to get cart line items in spree?

分類Dev

loopback 4 how to avoid creating more than 5 items in a shopping cart

分類Dev

How to create a shopping cart model with item variations

分類Dev

how to create shopping cart popup window in codeigniter

分類Dev

BeautifulSoup: How do I get different items from a <div>

分類Dev

How to get items from cart at homepage when there is NO API

分類Dev

how do I display the total of the whole cart

分類Dev

Magento shopping cart price rule buy $100 get free y

分類Dev

(Swift/iOS) Is it possible to get user purchased items from In app purchases?

分類Dev

How do I create a safe system on a used computer (running Windows 7) once purchased?

分類Dev

How do I run a Javascript event on Shopify Ajax cart update?

分類Dev

How do I get my search function work to filter searched items from table?

分類Dev

How do I drop items in collections in rust

分類Dev

WooCommerce Display Purchased Items Only

分類Dev

How do I trigger a GridView_CellContentClick event?

分類Dev

How to show woocommerce shopping cart with php but customize it by adding an icon and changing the text

分類Dev

Get the person type name from cart items in Woocommerce Bookings

分類Dev

Asp net, how do I list items in real time?

分類Dev

How do I join 2 tables to allocate items?

分類Dev

How do I remove certain items from the dictionary?

分類Dev

How do I display database items separated by an ID in Coldfusion?

分類Dev

How do I find the sum of items in a text file

分類Dev

How can I get nth child in array of items retrieved by class?

分類Dev

How do I calculate the total sum of my cart to my dictionary list based on user input menu?

分類Dev

yii2 shopping cart ajax

分類Dev

magento shopping cart multiple rules on same product

分類Dev

PHP shopping cart multiple values in one id

Related 関連記事

  1. 1

    How do I update my shopping cart with the product ID using an HTML form?

  2. 2

    Append cart, how do I discount certain items?

  3. 3

    How to get cart line items in spree?

  4. 4

    loopback 4 how to avoid creating more than 5 items in a shopping cart

  5. 5

    How to create a shopping cart model with item variations

  6. 6

    how to create shopping cart popup window in codeigniter

  7. 7

    BeautifulSoup: How do I get different items from a <div>

  8. 8

    How to get items from cart at homepage when there is NO API

  9. 9

    how do I display the total of the whole cart

  10. 10

    Magento shopping cart price rule buy $100 get free y

  11. 11

    (Swift/iOS) Is it possible to get user purchased items from In app purchases?

  12. 12

    How do I create a safe system on a used computer (running Windows 7) once purchased?

  13. 13

    How do I run a Javascript event on Shopify Ajax cart update?

  14. 14

    How do I get my search function work to filter searched items from table?

  15. 15

    How do I drop items in collections in rust

  16. 16

    WooCommerce Display Purchased Items Only

  17. 17

    How do I trigger a GridView_CellContentClick event?

  18. 18

    How to show woocommerce shopping cart with php but customize it by adding an icon and changing the text

  19. 19

    Get the person type name from cart items in Woocommerce Bookings

  20. 20

    Asp net, how do I list items in real time?

  21. 21

    How do I join 2 tables to allocate items?

  22. 22

    How do I remove certain items from the dictionary?

  23. 23

    How do I display database items separated by an ID in Coldfusion?

  24. 24

    How do I find the sum of items in a text file

  25. 25

    How can I get nth child in array of items retrieved by class?

  26. 26

    How do I calculate the total sum of my cart to my dictionary list based on user input menu?

  27. 27

    yii2 shopping cart ajax

  28. 28

    magento shopping cart multiple rules on same product

  29. 29

    PHP shopping cart multiple values in one id

ホットタグ

アーカイブ