方法一:
Private Sub dgd1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgd1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim ibtn As LinkButton
ibtn = CType(e.Item.Cells(6).Controls(0), LinkButton)
ibtn.Attributes.Add("onclick", "javascript:return confirm('确定删除" & e.Item.Cells(0).Text + "?');")
End If
End Sub
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim ibtn As LinkButton
ibtn = CType(e.Item.Cells(6).Controls(0), LinkButton)
ibtn.Attributes.Add("onclick", "javascript:return confirm('确定删除" & e.Item.Cells(0).Text + "?');")
End If
End Sub
方法二:
Private Sub datagrid_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid.ItemCreated
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
Dim myDeleteButton As ImageButton
myDeleteButton = e.Item.FindControl("btndelete")
myDeleteButton.ImageUrl = "image\delete.gif"
myDeleteButton.ToolTip = "删除此记录"
myDeleteButton.Attributes.Add("onclick", "return confirm('注意:此记录将被永久删除。您真的要删除第 " + CStr(e.Item.ItemIndex + 1) + " 行吗?');")
End Select
End Sub
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
Dim myDeleteButton As ImageButton
myDeleteButton = e.Item.FindControl("btndelete")
myDeleteButton.ImageUrl = "image\delete.gif"
myDeleteButton.ToolTip = "删除此记录"
myDeleteButton.Attributes.Add("onclick", "return confirm('注意:此记录将被永久删除。您真的要删除第 " + CStr(e.Item.ItemIndex + 1) + " 行吗?');")
End Select
End Sub