Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Error in executing action of deleting and updating data from GridView

Error in executing action of deleting and updating data from GridView

Scheduled Pinned Locked Moved ASP.NET
helpdesignannouncement
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    miss nadia
    wrote on last edited by
    #1

    I'm developing an e-commerce web-based system & have problem in Shopping Cart part. i.e. update quantity & delete item from cart. This is code-behind for my Cart.aspx. <pre> 'other code above Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting cart.DeleteItem(e.RowIndex) 'error here GridView1.DataBind() End Sub Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing GridView1.EditIndex = e.NewEditIndex GridView1.DataBind() End Sub Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating Dim cell As DataControlFieldCell cell = GridView1.Rows(e.RowIndex).Controls(3) Dim t As TextBox = cell.Controls(0) Try Dim q As Integer q = Integer.Parse(t.Text) cart.UpdateQuantity(e.RowIndex, q) 'error here Catch ex As FormatException e.Cancel = True End Try GridView1.EditIndex = -1 GridView1.DataBind() End Sub Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit e.Cancel = True GridView1.EditIndex = -1 GridView1.DataBind() End Sub 'other code below </pre> The error saying that: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Thanks for your help!

    A 1 Reply Last reply
    0
    • M miss nadia

      I'm developing an e-commerce web-based system & have problem in Shopping Cart part. i.e. update quantity & delete item from cart. This is code-behind for my Cart.aspx. <pre> 'other code above Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting cart.DeleteItem(e.RowIndex) 'error here GridView1.DataBind() End Sub Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing GridView1.EditIndex = e.NewEditIndex GridView1.DataBind() End Sub Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating Dim cell As DataControlFieldCell cell = GridView1.Rows(e.RowIndex).Controls(3) Dim t As TextBox = cell.Controls(0) Try Dim q As Integer q = Integer.Parse(t.Text) cart.UpdateQuantity(e.RowIndex, q) 'error here Catch ex As FormatException e.Cancel = True End Try GridView1.EditIndex = -1 GridView1.DataBind() End Sub Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit e.Cancel = True GridView1.EditIndex = -1 GridView1.DataBind() End Sub 'other code below </pre> The error saying that: Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Thanks for your help!

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      miss nadia wrote:

      cart.DeleteItem(e.RowIndex) 'error here

      Where is that function ?

      Best Regards ----------------- Abhijit Jana "Success is Journey it's not a destination"

      M 2 Replies Last reply
      0
      • A Abhijit Jana

        miss nadia wrote:

        cart.DeleteItem(e.RowIndex) 'error here

        Where is that function ?

        Best Regards ----------------- Abhijit Jana "Success is Journey it's not a destination"

        M Offline
        M Offline
        miss nadia
        wrote on last edited by
        #3

        That function is in ShoppingClass class.

        1 Reply Last reply
        0
        • A Abhijit Jana

          miss nadia wrote:

          cart.DeleteItem(e.RowIndex) 'error here

          Where is that function ?

          Best Regards ----------------- Abhijit Jana "Success is Journey it's not a destination"

          M Offline
          M Offline
          miss nadia
          wrote on last edited by
          #4

          this is the function in ShoppingCart class.

          Imports Microsoft.VisualBasic
          Imports System.Collections.Generic

          Public Class ShoppingCart

          Private \_cart As List(Of CartItem)
          
          Public Sub New()
              \_cart = New List(Of CartItem)()
          End Sub
          
          Public Function GetItems() As List(Of CartItem)
              Return \_cart
          End Function
          
          Public Sub AddItem(ByVal id As String, ByVal name As String, ByVal price As Decimal)
              Dim itemFound As Boolean = False
              For Each Item As CartItem In \_cart
                  If Item.ID = id Then
                      Item.Quantity += 1
                      itemFound = True
                  End If
              Next
              If Not itemFound Then
                  Dim item As CartItem
                  item = New CartItem(id, name, price, 1)
                  \_cart.Add(item)
              End If
          End Sub
          
          Public Sub UpdateQuantity(ByVal index As Integer, ByVal quantity As Integer)    'update quantity function
              Dim item As CartItem
              item = \_cart(index)
              item.Quantity = quantity
          End Sub
          
          Public Sub DeleteItem(ByVal index As Integer) 'delete item function
              \_cart.RemoveAt(index)
          End Sub
          
          Public ReadOnly Property Count() As Integer
              Get
                  Return \_cart.Count
              End Get
          End Property
          

          End Class

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups