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:
编辑:以下是要遵循的步骤:
- Create your image button in RowCreated
- Assign the CommandName and CommandArgument of your image button in RowDataBound
- In RowCommand check the image buttons CommandArgument for that row and you should see the ID that you previously stored there.
在RowCreated中创建图像按钮
在RowDataBound中分配图像按钮的CommandName和CommandArgument
在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:
编辑:以下是要遵循的步骤:
- Create your image button in RowCreated
- Assign the CommandName and CommandArgument of your image button in RowDataBound
- In RowCommand check the image buttons CommandArgument for that row and you should see the ID that you previously stored there.
在RowCreated中创建图像按钮
在RowDataBound中分配图像按钮的CommandName和CommandArgument
在RowCommand中,检查该行的图像按钮CommandArgument,您应该看到之前存储的ID。