I have a datagrid that lists documents: Document Name, User Name, Date. When a user clicks on the row of the document it opens in word, excel, etc. The datagrid also has a delete command column. The problem is, after clicking and confirming the delete, the 'open document' also executes. I have been trying to figure out how to not execute the 'open document' function when the user clicked on the delete column. Everything is working, except for having to cancel the document open dialog after the delete. I was trying to see if I could cancel the 'open document' function based on the cell clicked (if it was the delete column), but haven't been able to determine how to do that. Here is the code:
Code:
Private Sub dgDocuments_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgDocuments.DeleteCommand
' Deletes the document
Dim doc As New Document
Dim lDocID As Label
lDocID = CType(e.Item.Cells(0).FindControl("lblDocID"), Label)
doc.DocID = Convert.ToInt32(lDocID.Text)
doc.Delete()
BindDocGrid()
End Sub
Private Sub dgDocuments_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgDocuments.ItemDataBound
Dim lDocID As Label
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
' Get document id
lDocID = CType(e.Item.Cells(0).FindControl("lblDocID"), Label)
' function to open a document when a row is clicked
e.Item.Attributes.Add("onclick", "OpenGridDocument(" & lDocID.Text & ")")
End If
function OpenGridDocument(docid) {
var winURL = "viewDocument.aspx?ID=" + docid;
window.open(winURL);
}