Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to attach Javascript onto Delete Button in GridView ?

How to attach Javascript onto Delete Button in GridView ?

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptdesigntutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vicky457
    wrote on last edited by
    #1

    Hi, I just switched from .Net 1.1 to .Net 2.0. I want to attach Javascript onto Delete button in GridView so that the user will be able to confirm if he really wants to delete the record. However, I couldn't find ItemCreated event, which is presented in Datagrid. Here is my code used in Datagrid: Private Sub dgContainer_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgContainer.ItemCreated If e.Item.ItemIndex > -1 And Not e.Item.ItemType = ListItemType.EditItem Then Dim DeleteButton As LinkButton = e.Item.Cells(6).Controls(0) 'Attach javascript onto OnClick event DeleteButton.Attributes("OnClick") = "javascript:return confirm('Deleting this client will delete all the information related the client. Do you really want to delete " & _ Chr(34) & Trim(dgContainer.DataKeys(e.Item.ItemIndex)) & Chr(34) & "?')" End If End Sub Does anyone know how to do this in GridView? Thank you in advance!

    E 1 Reply Last reply
    0
    • V vicky457

      Hi, I just switched from .Net 1.1 to .Net 2.0. I want to attach Javascript onto Delete button in GridView so that the user will be able to confirm if he really wants to delete the record. However, I couldn't find ItemCreated event, which is presented in Datagrid. Here is my code used in Datagrid: Private Sub dgContainer_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgContainer.ItemCreated If e.Item.ItemIndex > -1 And Not e.Item.ItemType = ListItemType.EditItem Then Dim DeleteButton As LinkButton = e.Item.Cells(6).Controls(0) 'Attach javascript onto OnClick event DeleteButton.Attributes("OnClick") = "javascript:return confirm('Deleting this client will delete all the information related the client. Do you really want to delete " & _ Chr(34) & Trim(dgContainer.DataKeys(e.Item.ItemIndex)) & Chr(34) & "?')" End If End Sub Does anyone know how to do this in GridView? Thank you in advance!

      E Offline
      E Offline
      ednrgc
      wrote on last edited by
      #2

      Check this article: http://aspnet.4guysfromrolla.com/articles/021104-1.aspx

      K V 2 Replies Last reply
      0
      • E ednrgc

        Check this article: http://aspnet.4guysfromrolla.com/articles/021104-1.aspx

        K Offline
        K Offline
        kaliem
        wrote on last edited by
        #3

        Enable "AutoPostBack" for the Combo Box you made. can be done through its properties box. By default, this is not enabled ... btw, what would happen if it was enabled by default ... what were going in their minds .. can someone suggest ... kaliem

        K 1 Reply Last reply
        0
        • K kaliem

          Enable "AutoPostBack" for the Combo Box you made. can be done through its properties box. By default, this is not enabled ... btw, what would happen if it was enabled by default ... what were going in their minds .. can someone suggest ... kaliem

          K Offline
          K Offline
          kaliem
          wrote on last edited by
          #4

          sorry, posted at wrong place .. pardon ...

          1 Reply Last reply
          0
          • E ednrgc

            Check this article: http://aspnet.4guysfromrolla.com/articles/021104-1.aspx

            V Offline
            V Offline
            vicky457
            wrote on last edited by
            #5

            Thanks! I got it.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups