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. Item events from a DataGrid

Item events from a DataGrid

Scheduled Pinned Locked Moved ASP.NET
javascriptquestion
8 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.
  • P Offline
    P Offline
    PeteConc
    wrote on last edited by
    #1

    Hello. I have a DataGrid in my aspx page and I added the following javascript code at the end of the file: elem = window.document.getElementById("myDatagrid"); rows = elem.document.getElementsByTagName("tr"); rows.item(10).style.backgroundColor = "green"; rows.item(10).onclick = "javascript:alert(\"ok\")"; What it's supposed to do is chaging the background of line 10 and, when clicked, display an alert. The background change works fine, but the 'onclick' event doesn't do anything. What am I missing here? Thanks.

    P 1 Reply Last reply
    0
    • P PeteConc

      Hello. I have a DataGrid in my aspx page and I added the following javascript code at the end of the file: elem = window.document.getElementById("myDatagrid"); rows = elem.document.getElementsByTagName("tr"); rows.item(10).style.backgroundColor = "green"; rows.item(10).onclick = "javascript:alert(\"ok\")"; What it's supposed to do is chaging the background of line 10 and, when clicked, display an alert. The background change works fine, but the 'onclick' event doesn't do anything. What am I missing here? Thanks.

      P Offline
      P Offline
      PeteConc
      wrote on last edited by
      #2

      Just to add that the code i'm running is: rows.item(10).onclick = "javascript: alert(\"ok\")"; and not: rows.item(10).onclick = "javascriptalert(\"ok\")";

      G 2 Replies Last reply
      0
      • P PeteConc

        Just to add that the code i'm running is: rows.item(10).onclick = "javascript: alert(\"ok\")"; and not: rows.item(10).onclick = "javascriptalert(\"ok\")";

        G Offline
        G Offline
        Gavin Jeffrey
        wrote on last edited by
        #3

        Try - rows.item(10).onclick = "javascript:alert(\"ok\")";

        1 Reply Last reply
        0
        • P PeteConc

          Just to add that the code i'm running is: rows.item(10).onclick = "javascript: alert(\"ok\")"; and not: rows.item(10).onclick = "javascriptalert(\"ok\")";

          G Offline
          G Offline
          Gavin Jeffrey
          wrote on last edited by
          #4

          Well now my previous post was absolutely useless...let me try again - javascript:alert() if that doesnt work try viewing your source to see what the actual html looks like.

          A 1 Reply Last reply
          0
          • G Gavin Jeffrey

            Well now my previous post was absolutely useless...let me try again - javascript:alert() if that doesnt work try viewing your source to see what the actual html looks like.

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Dammit!! last try before i give up and go home (its past my wrking hour now) - javascript :alert()

            P 1 Reply Last reply
            0
            • A Anonymous

              Dammit!! last try before i give up and go home (its past my wrking hour now) - javascript :alert()

              P Offline
              P Offline
              PeteConc
              wrote on last edited by
              #6

              It seems that the 'doublequote' is being automatically ommited by some process. So assume it is there. =) Anyway, it doesn't work. I can't manage how to use the onclick event correctly. =( Other suggestions would be very useful. Thanks very much.

              A 1 Reply Last reply
              0
              • P PeteConc

                It seems that the 'doublequote' is being automatically ommited by some process. So assume it is there. =) Anyway, it doesn't work. I can't manage how to use the onclick event correctly. =( Other suggestions would be very useful. Thanks very much.

                A Offline
                A Offline
                Anonymous
                wrote on last edited by
                #7

                why dont u override IteDatabound event and then add attributes for items in CS file, i think u just want to add javascript event for some rows or every row, then y dont u do like this private void dgTasks_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { //on every column , applying the change class e.Item.Attributes["onmouseover"] = "changeClass(this, 'RecordTableRowHeighlighted');"; e.Item.Attributes["onmouseout"] = "changeClass(this, 'RecordTableRowNormal');"; e.Item.Attributes["onclick"] = "javascript:alert()"; } }

                P 1 Reply Last reply
                0
                • A Anonymous

                  why dont u override IteDatabound event and then add attributes for items in CS file, i think u just want to add javascript event for some rows or every row, then y dont u do like this private void dgTasks_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { //on every column , applying the change class e.Item.Attributes["onmouseover"] = "changeClass(this, 'RecordTableRowHeighlighted');"; e.Item.Attributes["onmouseout"] = "changeClass(this, 'RecordTableRowNormal');"; e.Item.Attributes["onclick"] = "javascript:alert()"; } }

                  P Offline
                  P Offline
                  PeteConc
                  wrote on last edited by
                  #8

                  That method was very easy and useful. Thanks for your suggestion.

                  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