[Datagrid Onclick Error]

D

DK

Hi all,

Anyone know how to solve the datagrid onclick problem as below:
i click a row in a datagrid then the row change to another color, but
when i click on another row, the previous row that i clicked still red
color, so now have two row that red in color.
what I want is the previous row that i clicked change back to its
original color without post back the page.
I am using code below:

<script language="JavaScript">
var lastColorUsed;
function prettyDG_changeBackColor(row, highlight)
{
if (highlight)
{
lastColorUsed = row.style.backgroundColor;

row.style.backgroundColor = 'pink';
}
else
if (row.style.backgroundColor == 'pink')
{
row.style.backgroundColor = lastColorUsed;
}
}


var lastRowSelected;
var lastRowSelectedColorUsed;
function prettyDG_changeBackColor2(row)
{
var color = lastRowSelectedColorUsed;
lastRowSelectedColorUsed= row.style.backgroundColor;
row.style.backgroundColor = 'aqua';

lastRowSelected = row;
if (lastRowSelected != null)
{
lastRowSelected.backgroundColor = color;
lastRowSelected = row;
}
}
</script>

while the code behind as below:

e.Item.Attributes.Add("onmouseover",
"prettyDG_changeBackColor(this, true);")
e.Item.Attributes.Add("onmouseout",
"prettyDG_changeBackColor(this, false);")
e.Item.Attributes.Add("onclick",
"prettyDG_changeBackColor2(this, true);")


The logic is when mouse over, the row become 'pink' color,
when mouse out, if the row color is 'Pink' then change to transparent
else don't change color
when clicked, the row become 'Aqua' color.

Please advice on how to change back the 'Aqua' to transparent color if
we clicked on another row, this mean there will not more than 1 row
with 'Aqua' color.
 
D

DK

Dear Datagrid experts,

Do you have any idea about this issue, kindly help. Thanks in
advance...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top