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

时间:2022-04-21 14:46:00

I have a gridview and in that gridview i created a list of imagebuttons programmatically with an addhandler as follows:

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

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

my issue is getting the value of the row of the clicked imagebutton in the click handler. How do i get that?

我的问题是获取点击处理程序中单击的图像按钮的行的值。我怎么做到的?

1 个解决方案

#1


I'd recommend assigning

我建议分配

imageButton.CommandName = "Delete"
imageButton.CommandArgument = Your_Row_ID_You_Want_To_Get

and then using the imageButton.OnCommand to do your work.

然后使用imageButton.OnCommand来完成你的工作。

Edit: Here are the steps to follow:

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

  1. Create your image button in RowCreated
  2. 在RowCreated中创建图像按钮

  3. Assign the CommandName and CommandArgument of your image button in RowDataBound
  4. 在RowDataBound中分配图像按钮的CommandName和CommandArgument

  5. In RowCommand check the image buttons CommandArgument for that row and you should see the ID that you previously stored there.
  6. 在RowCommand中,检查该行的图像按钮CommandArgument,您应该看到之前存储的ID。

#1


I'd recommend assigning

我建议分配

imageButton.CommandName = "Delete"
imageButton.CommandArgument = Your_Row_ID_You_Want_To_Get

and then using the imageButton.OnCommand to do your work.

然后使用imageButton.OnCommand来完成你的工作。

Edit: Here are the steps to follow:

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

  1. Create your image button in RowCreated
  2. 在RowCreated中创建图像按钮

  3. Assign the CommandName and CommandArgument of your image button in RowDataBound
  4. 在RowDataBound中分配图像按钮的CommandName和CommandArgument

  5. In RowCommand check the image buttons CommandArgument for that row and you should see the ID that you previously stored there.
  6. 在RowCommand中,检查该行的图像按钮CommandArgument,您应该看到之前存储的ID。