By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,132 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,132 IT Pros & Developers. It's quick & easy.

How to cancel a javascript initiated from a datagrid based on cell clicked?

P: 5
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:

Expand|Select|Wrap|Line Numbers
  1.         Private Sub dgDocuments_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgDocuments.DeleteCommand
  2. ' Deletes the document
  3.             Dim doc As New Document
  4.             Dim lDocID As Label
  5.             lDocID = CType(e.Item.Cells(0).FindControl("lblDocID"), Label)
  6.             doc.DocID = Convert.ToInt32(lDocID.Text)
  7.             doc.Delete()
  8.             BindDocGrid()
  9.         End Sub
  10.  
  11.         Private Sub dgDocuments_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgDocuments.ItemDataBound
  12.  
  13.             Dim lDocID As Label
  14.             If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
  15.                 ' Get document id
  16.              lDocID = CType(e.Item.Cells(0).FindControl("lblDocID"), Label)
  17.                 ' function to open a document when a row is clicked
  18.                 e.Item.Attributes.Add("onclick", "OpenGridDocument(" & lDocID.Text & ")")
  19.  
  20.             End If
  21.  
  22.  
  23. function OpenGridDocument(docid) {
  24.         var winURL = "viewDocument.aspx?ID=" + docid;
  25.         window.open(winURL);
  26. }
  27.  
Jan 21 '11 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.