View Full Version : Help in this code

Nov 19th, 2009, 05:03 PM
I have a java script code that highlights each row after it is selected by a checkbox
( i am using a control called gridview in asp.net )

i want the code to perform two things
1- highlight the row when it is selected ( when the checkbox status is checked ) .
2- cancel the highlighting when the checkbox is deselected again ( when the checkbox status is unchecked ) .

the code already makes the first thing successfully
my problem is in the second case ( i mean when the checkbox is unchecked ) the color (highlighting ) doesn't change .
here is the function

function Check_Click(objRef)
//Get the Row based on checkbox
var row = objRef.parentNode.parentNode;

//Get the reference of GridView
var GridView = row.parentNode;

//Get all input elements in Gridview
var inputList = GridView.getElementsByTagName("input");

for (var i=0;i<inputList.length;i++)


//The First element is the Header Checkbox
var headerCheckBox = inputList[0];

//Based on all or none checkboxes
//are checked check/uncheck Header Checkbox
var checked = true;
if(inputList[i].type == "checkbox" && inputList[i] != headerCheckBox)
row.style.backgroundColor = "#C2D69B";

checked = false;


headerCheckBox.checked = checked;

please help me .. i need this code
thanks in advance

Old Pedant
Nov 19th, 2009, 10:07 PM
Please help us help you...

Bring up the page in your browser, then click on VIEW menu, then on SOURCE menu item.

Find the HTML code that correseponds to your GRIDVIEW and show us what it looks like.

(If you have tons of rows in the grid, just show 2 or 3 of them, please.)

But in any case, I see nothing in that code that would reset the background color.

*PROBABLY* the better way to do this would be to change the className of the entire row, so it might be good to show us the CSS (the portion of the <style>s) that is relevant to this row, as well.

Philip M
Nov 20th, 2009, 08:47 AM
And please help us to help you by following the posting guidelines and wrapping your code in [code] tags. This means use the octothorpe or # button on the toolbar which will insert opening [ code ] and closing [ /code ] tags - omit the spaces. You can (and should) edit your previous post.