Item events from a DataGrid
-
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.
-
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.
-
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\")";
Try - rows.item(10).onclick = "javascript:alert(\"ok\")";
-
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\")";
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. -
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. -
Dammit!! last try before i give up and go home (its past my wrking hour now) -
javascript :alert()
-
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.
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()"; } }
-
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()"; } }