Microsoft Access: Using "On Row Deleted" etc.

  • deathcab1 / 102 / Fri, 27 Mar 2009 12:16:00 GMT / Comments (7)
  • Hi, i currently have a shopping cart in a grid view, (which i made following a tutorial). In the current gridview, it has all the obvious fields, and one button field with "OnSelectedIndexChanged="RemoveCartItem" .and then

    <asp:ButtonField

    CommandName="select"

    Text="Delete item"/>

    Now this works, i click the button and it runs the removeCartItem Sub and it deletes the item. I figured that this is a bit...unefficient since the OnSelected is supposed to be used when clicking the select button.

    I tried switching it to "onRowDeleted="RemoveCartItem", so i could free up select for other things (as well as the fact i want to add others for editing etc) but as soon as i switch to onRowDeleted i get the following error:

    Compilation Error

    Description:An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message:BC30408: Method 'Public Sub RemoveCartItem(s As Object, e As System.EventArgs)' does not have the same signature as delegate 'Delegate Sub GridViewDeletedEventHandler(sender As Object, e As System.Web.UI.WebControls.GridViewDeletedEventArgs)'.

    -----------

    So i'm assuming my sub doesn't follow the standard for the delete command or something?. my sub is:

    Sub RemoveCartItem(ByVal sAsObject,ByVal eAs EventArgs)Dim IDAsString =CInt(CartGrid.SelectedDataKey.Value)

    Profile.ShoppingCart.RemoveItem(ID)

    BindShoppingCart()

    Response.Redirect(
    "cart.aspx")

    EndSub

    --

    And this is in a sperate class file:

    -

    PublicSub RemoveItem(ByVal IDAsInteger)

    Dim itemAs CartItem =CType(_CartItems(ID), CartItem)

    If itemIsNothingThen

    Return

    EndIf

    If item.Quantity >= 0Then

    _CartItems.Remove(ID)

    Else

    _CartItems(ID) = item

    EndIf

    EndSub

    -------

  • Keywords:

    row, deleted, microsoft, access

  • http://www.edevs.com/ms-access-database/284/«« Last Thread - Next Thread »»
    1. Hi

      Yes the message is correct... every event is implemented as delegate.. and your custom method signature is not matching the expected delegate signature.. pls see if this helps

      change your method declaration to

      Sub RemoveCartItem(ByVal sAsObject,ByVal e As System.Web.UI.WebControls.GridViewDeletedEventArgs)

      When calling this method call it as

      RemoveCartItem(GridView1,EventArgs.Empty)

      Hope this helps.

      VJ

      vijayvrr_2001 | Sun, 06 Jan 2008 10:04:00 GMT |

    2. deathcab1:
      Method 'Public Sub RemoveCartItem(s As Object, e As System.EventArgs)' does not have the same signature as delegate 'Delegate Sub GridViewDeletedEventHandler(sender As Object, e As System.Web.UI.WebControls.GridViewDeletedEventArgs)

      The error tells you what the problem is. This:

      s As Object, e As System.EventArgs

      isn't the same as what the delete method should have i.e.

      sender As Object, e As System.Web.UI.WebControls.GridViewDeletedEventArgs

      ca8msm | Sun, 06 Jan 2008 10:05:00 GMT |

    3. i changed the following:

      Sub RemoveCartItem(ByVal sAsObject,ByVal eAs System.Web.UI.WebControls.GridViewDeletedEventArgs)Dim IDAsString =CInt(CartGrid.SelectedDataKey.Value)

      Profile.ShoppingCart.RemoveItem(ID)

      BindShoppingCart()

      Response.Redirect(
      "cart.aspx")

      EndSub

      and

      OnRowDeleted="RemoveCartItem(GridView1,EventArgs.Empty)"

      . but im still getting the same error. when im doing removeItem in the method, should i remove name, quantity etc, as well as the ID?, or is the ID enough

      deathcab1 | Sun, 06 Jan 2008 10:06:00 GMT |

    4. oh, i changed the ID to the ID of my grid view and that error has now gone, but i have:

      Error 28 'AddressOf' operand must be the name of a method (without parentheses). C:\Safle2\Cart.aspx 58

      deathcab1 | Sun, 06 Jan 2008 10:07:00 GMT |

    5. Hi

      I am not too sure how to do it declaratively (as a part of the definition), but can you try this programatically, which is

      Sub Page_Load

      AddHandler <your gridview name>.RowDeleted, AddressOf RemoveItem

      ' Note: (No paranthesis after RemoveItem)

      End Sub

      VJ

      vijayvrr_2001 | Sun, 06 Jan 2008 10:08:00 GMT |

    6. hmm, that doesnt seem to work either. RemoveItem needed to be declared, but i changed that to the name of my method (removeCartItem) and no problem, just the addressOf error appears again.

      Sub Page_Load()

      AddHandler CartGrid.RowDeleted,AddressOf RemoveCartItem

      Error 28 'AddressOf' operand must be the name of a method (without parentheses). C:\Safle\Cart.aspx 56

      but that is the name of my method - Remove cart item

      deathcab1 | Sun, 06 Jan 2008 10:09:00 GMT |

    7. Hideathcab1 ,

      There are many other ways to define a button to delete. My suggestion is to put a button in ItemTemplate then set CommandName to any string except delete,insert and update. You can write some codes behind to delete records.

      Have a look at my sample,

       <asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("id")%>' CommandName="del">delete</asp:LinkButton> </ItemTemplate> </asp:TemplateField>

      protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
      {
      if (e.CommandName == "del")
      {
      string id = e.CommandArgument.ToString();
      //delete here
      }

      }

      samuzhang_msft | Sun, 06 Jan 2008 10:10:00 GMT |