views:

437

answers:

1

I have an image button that is created on rowcreated manually in code.

Dim deletecshr As New ImageButton
    deletecshr.ImageUrl = "\images\bttnDeletemini.gif"
    deletecshr.ToolTip = "This Will Delete All Cashiers"
    deletecshr.ID = "deletecshr"

In gridveiw_rowdatabound I have the following:

Dim deletecshr As ImageButton = DirectCast(e.Row.FindControl("deletecshr"), ImageButton)
            deletecshr.CommandName = "Delete"
            deletecshr.CommandArgument = emp_no & "," & e.Row.Cells(2).Text & "," & e.Row.Cells(1).Text & "," & cashier_no & "," & manager_no

I set the commandname and the argument.

However, in rowcommand it finds no commandname or anything else. What am i doing wrong? I believe this has worked before.

+2  A: 

From what i can tell you never attach the event.

Dim deletecshr As New ImageButton
deletecshr.ImageUrl = "\images\bttnDeletemini.gif"
deletecshr.ToolTip = "This Will Delete All Cashiers"
deletecshr.ID = "deletecshr"
AddHandler deletecshr.Command AddressOf deletecshrCommandEventHandler

You'll have a method similar of this in your code:

Protected Sub deletecshrCommandEventHandler(sender As Object, e As CommandEventArgs)
  If e.CommandName = "Delete" Then

    'Do your stuff

  End IF
End Sub

EDIT
Added some more code and fixed a small syntax error.

Sani Huttunen
This didn't work. there is no .RowCommand being that it is an image button.
Eric
Sorry... it's just Command...
Sani Huttunen
This is a pretty good answer, i just can't get the argument
Eric
Thank you! I eventually got it to work using your idea. thanks
Eric