从vb.net中gridview中的图像按钮获取行的Id

从vb.net中gridview中的图像按钮获取行的Id,vb.net,gridview,imagebutton,Vb.net,Gridview,Imagebutton,我有一个gridview,在该gridview中,我使用addhandler以编程方式创建了一个imagebuttons列表,如下所示: Dim deletecshr As New ImageButton deletecshr.ImageUrl = "\images\bttnDeletemini.gif" deletecshr.ToolTip = "This Will Delete All Cashiers" AddHandler deletecshr.Click, AddressOf dele

我有一个gridview,在该gridview中,我使用addhandler以编程方式创建了一个imagebuttons列表,如下所示:

Dim deletecshr As New ImageButton
deletecshr.ImageUrl = "\images\bttnDeletemini.gif"
deletecshr.ToolTip = "This Will Delete All Cashiers"
AddHandler deletecshr.Click, AddressOf deletecshr_Click
deletecshr.Attributes.Add("onclick", "javascript: if(confirm('Are you sure you want to delete all of these cashiers?')==false) return false;")

    If e.Row.Cells.Count > 2 And e.Row.RowType <> DataControlRowType.Header And e.Row.RowType <> DataControlRowType.Footer Then
        e.Row.Cells(3).Controls.Add(deletecshr)
    End If
Dim deleteChr As New image按钮
deletecshr.ImageUrl=“\images\bttnDeletemini.gif”
deletecshr.ToolTip=“这将删除所有出纳”
AddHandler deletecshr.单击,地址deletecshr\u单击
deletecshr.Attributes.Add(“onclick”,“javascript:if(confirm('您确定要删除所有这些出纳吗?')==false)return false;”)
如果e.Row.Cells.Count>2且e.Row.RowType DataControlRowType.Header和e.Row.RowType DataControlRowType.Footer,则
e、 行。单元格(3)。控件。添加(删除CSHR)
如果结束

我的问题是获取单击处理程序中单击的imagebutton行的值。我怎样才能得到呢?

我建议分配

imageButton.CommandName = "Delete"
imageButton.CommandArgument = Your_Row_ID_You_Want_To_Get
然后使用imageButton.OnCommand来完成您的工作

编辑: 以下是要遵循的步骤:

  • 在创建的行中创建图像按钮
  • 在RowDataBound中指定图像按钮的CommandName和CommandArgument
  • 在RowCommand中,检查该行的image buttons CommandArgument,您应该会看到以前存储在那里的ID

  • 我建议你分配

    imageButton.CommandName = "Delete"
    imageButton.CommandArgument = Your_Row_ID_You_Want_To_Get
    
    然后使用imageButton.OnCommand来完成您的工作

    编辑: 以下是要遵循的步骤:

  • 在创建的行中创建图像按钮
  • 在RowDataBound中指定图像按钮的CommandName和CommandArgument
  • 在RowCommand中,检查该行的image buttons CommandArgument,您应该会看到以前存储在那里的ID

  • 我应该说得更具体些。我查看了这个示例,但无法获取Id,因为按钮不在我的源代码中,因为按钮是在Gridview上以编程方式生成的。这就是我必须创建并添加Handler的原因。感谢您的快速响应。请尝试使用GridView RowDataBound事件为按钮创建与行ID的绑定,因为您将无法访问已创建行中的信息。Adam这非常有效。我无法使用我创建的addhandler,但我可以使用Gridview_RowCommand来编写命令。但是,如何获取选定行的id以删除数据库中的记录。我尝试了Gridview.SelectedDataKey,设置了datakeynames,并尝试了Gridview.SelectedValue…两者都不起作用。再次感谢。亚当,谢谢你的帮助。我试着投你的票,但我的声望不够高。你的脚步确实帮了我,不用担心。很高兴能帮上忙。祝项目顺利!我应该说得更具体些。我查看了这个示例,但无法获取Id,因为按钮不在我的源代码中,因为按钮是在Gridview上以编程方式生成的。这就是我必须创建并添加Handler的原因。感谢您的快速响应。请尝试使用GridView RowDataBound事件为按钮创建与行ID的绑定,因为您将无法访问已创建行中的信息。Adam这非常有效。我无法使用我创建的addhandler,但我可以使用Gridview_RowCommand来编写命令。但是,如何获取选定行的id以删除数据库中的记录。我尝试了Gridview.SelectedDataKey,设置了datakeynames,并尝试了Gridview.SelectedValue…两者都不起作用。再次感谢。亚当,谢谢你的帮助。我试着投你的票,但我的声望不够高。你的脚步确实帮了我,不用担心。很高兴能帮上忙。祝项目顺利!