Click here to Skip to main content
15,915,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a grid view which is binding from a dataset.

I have taken a span tag like this
C#
<span>demo text</span>


when gridview or datalist bound at that time i want to call client side function, and based on span value it's color i want to change

my client side function like this
JavaScript
fucntion spancolorchange(spanid){

// here color change code
.....
....

}
Posted
Updated 5-Feb-12 19:51pm
v2
Comments
Martin Arapovic 6-Feb-12 2:07am    
Hi! You can't call javascript when gridview or datalist are bounded. Javascript is executed on client and there is nothing to do with server-side processing. You must call it on page load, some control click, onmouseover, keypress or any other event that fits your needs. So if you want to change coors of these spans best way is to chage it on dom.ready or do that on server side while you binding gridview. Look GridView OnRowDataBoundEvent for example...

Yes. By reading the value from the HTML tags generated for the gridview, you can assign them colors , dynamically, from the javascript.


http://www.mindfiresolutions.com/How-to-set-alternative-row-color-of-grid-using-jQuery-193.php[^]
 
Share this answer
 
use
JavaScript
document.getElementById('<%=yourGridID.ClientID%>').style.backgroundColor=document.getElementById('yourspanID').innerHTML;
 
Share this answer
 
v2
Comments
Surendra Tarai 6-Feb-12 1:59am    
dear sanjay, u may not get my question??
i want to call a client side function from gridview, then in that client side function i can change color based on value ???/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900