Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 28, 2012 07:45 PM by omerdemir
Member
271 Points
528 Posts
Apr 28, 2012 01:06 PM|LINK
Hello!
Trying to highlight my gridview rows with this code but getting error
can you help me?
<script type="text/javascript"> window.onload = function() { var hiliclass = "Hilightrow"; var trhilight = document.getElementById("gvAll").getElementsByTagName("tr"); var len = trhilight.length; for (var i = 0; i < len; i++) { if (trhilight[i].className == hiliclass) { trhilight[i].onmouseover = function () { trhilight[i].style.backgroundColor = "red"; } } } } </script>
All-Star
42941 Points
7024 Posts
MVP
Apr 28, 2012 01:16 PM|LINK
Hello,
omerdemir Trying to highlight my gridview rows with this code but getting error can you help me?
We can try. But what's the error??? How do we suppose to help you without knowing the problem?
omerdemir var trhilight = document.getElementById("gvAll").getElementsByTagName("tr");
What is "gvAll"? If it's the ID of GridView, try the below
var trhilight = document.getElementById("<%=gvAll.ClientID%>").getElementsByTagName("tr");
If that doesn't help, please post your aspx code (mark up) too and describe what's happening.
Please 'Mark as Answer' if this post helps you.
Apr 28, 2012 01:22 PM|LINK
Thank you for your prompt response.
Error is in the subject. gv is my gridview. and i getting this error
in this row
trhilight[i].style.backgroundColor = "#red";
i added this codes too i mean page adding "Hilightrow CssClass" to all tr tags..
tried ("<%=gvAll.ClientID%>") but no luck (
Apr 28, 2012 01:39 PM|LINK
omerdemir getElementsByTagName("tr")
Hi,
In webkit browsers (Chrome, safari etc.), getElementsByTagName return a NodeList. So you may have to alter that to use
trhilight[i].childNodes[0].style.backgroundColor = "red";
Apr 28, 2012 01:46 PM|LINK
Hi
Thanks for information and support.
But did not work!
Tried this
and get this
Microsoft JScript runtime error: Unable to get value of the property 'childNodes': object is null or undefined
Thanks again
Apr 28, 2012 02:00 PM|LINK
Hmm.. That's weird. I tried the very basic of your javascript code and it works fine for me in Chrome.
function test() { var x = document.getElementsByTagName("tr"); for (var i = 0; i < x .length; i++) { x[i].style.backgroundColor = "red"; } }
What's the browser you are using? It seems like you are testing this on IE.
Apr 28, 2012 07:45 PM|LINK
Thank you for reply.
omerdemir
Member
271 Points
528 Posts
Unable to get value of the property 'style': object is null or undefined
Apr 28, 2012 01:06 PM|LINK
Hello!
Trying to highlight my gridview rows with this code but getting error
can you help me?
<script type="text/javascript"> window.onload = function() { var hiliclass = "Hilightrow"; var trhilight = document.getElementById("gvAll").getElementsByTagName("tr"); var len = trhilight.length; for (var i = 0; i < len; i++) { if (trhilight[i].className == hiliclass) { trhilight[i].onmouseover = function () { trhilight[i].style.backgroundColor = "red"; } } } } </script>Ruchira
All-Star
42941 Points
7024 Posts
MVP
Re: Unable to get value of the property 'style': object is null or undefined
Apr 28, 2012 01:16 PM|LINK
Hello,
We can try. But what's the error??? How do we suppose to help you without knowing the problem?
What is "gvAll"? If it's the ID of GridView, try the below
var trhilight = document.getElementById("<%=gvAll.ClientID%>").getElementsByTagName("tr");If that doesn't help, please post your aspx code (mark up) too and describe what's happening.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.omerdemir
Member
271 Points
528 Posts
Re: Unable to get value of the property 'style': object is null or undefined
Apr 28, 2012 01:22 PM|LINK
Thank you for your prompt response.
Error is in the subject. gv is my gridview. and i getting this error
in this row
trhilight[i].style.backgroundColor = "#red";
i added this codes too i mean page adding "Hilightrow CssClass" to all tr tags..
tried ("<%=gvAll.ClientID%>") but no luck (
Ruchira
All-Star
42941 Points
7024 Posts
MVP
Re: Unable to get value of the property 'style': object is null or undefined
Apr 28, 2012 01:39 PM|LINK
Hi,
In webkit browsers (Chrome, safari etc.), getElementsByTagName return a NodeList. So you may have to alter that to use
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.omerdemir
Member
271 Points
528 Posts
Re: Unable to get value of the property 'style': object is null or undefined
Apr 28, 2012 01:46 PM|LINK
Hi
Thanks for information and support.
But did not work!
Tried this
trhilight[i].childNodes[0].style.backgroundColor = "red";
and get this
Microsoft JScript runtime error: Unable to get value of the property 'childNodes': object is null or undefined
Thanks again
Ruchira
All-Star
42941 Points
7024 Posts
MVP
Re: Unable to get value of the property 'style': object is null or undefined
Apr 28, 2012 02:00 PM|LINK
Hmm.. That's weird. I tried the very basic of your javascript code and it works fine for me in Chrome.
function test() { var x = document.getElementsByTagName("tr"); for (var i = 0; i < x .length; i++) { x[i].style.backgroundColor = "red"; } }What's the browser you are using? It seems like you are testing this on IE.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.omerdemir
Member
271 Points
528 Posts
Re: Unable to get value of the property 'style': object is null or undefined
Apr 28, 2012 07:45 PM|LINK
Thank you for reply.