我的rowcommand没有gridview的命令名

时间:2009-07-01 15:22:36

标签: asp.net vb.net visual-studio-2008 gridview

我有一个在代码中手动创建的图像按钮。

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

在gridveiw_rowdatabound中,我有以下内容:

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

我设置了commandname和参数。

但是,在rowcommand中它找不到命令名或其他任何内容。我究竟做错了什么?我相信这之前已经奏效。

1 个答案:

答案 0 :(得分:2)

据我所知,你永远不会附上活动。

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

您的代码中会有类似的方法:

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

    'Do your stuff

  End IF
End Sub

修改
添加了一些代码并修复了一个小的语法错误。