Datagrid control to change the row color on Mouse click event

K

karunakar

Hi All,

I want to deselect the row in DATAGRID. in ASP.NET application.
I was alredy selected in datagrid row .I want to change another row in same
datgrid .
Here in my datagrid was selected in Multiple rows. when ever i select the
particular row that time it can be selected .Next time i want to choose
another datagrid row that time in My application first row also
hilighted.(Here Multiple
rows selected) that should not happen

I want to Deselect first row in DataGrid.

I was done like this :


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

row.style.backgroundColor = 'pink';
}
else
row.style.backgroundColor = lastColorUsed;
}
</script>


if(e.Item.ItemType==ListItemType.Item ||
e.Item.ItemType==ListItemType.AlternatingItem)

{

e.Item.Attributes["onmouseover"] =
"javascript:prettyDG_changeBackColor(this, true);";

e.Item.Attributes["onmouseout"] = "javascript:prettyDG_changeBackColor(this,
false);";

e.Item.Attributes["onclick"] = "javascript:prettyDG_changeBackColor(this,
true);";

}



Thank you
Karunakara Rao
 
E

Eliyahu Goldin

Karunakara,

First of all you should be using different colors for onclick and
onmouseover events. Otherwise you will have 2 pink records: one that is
selected and another one where the mouse is. Than you can leave
prettyDG_changeBackColor for onmouseover and onmouseout event and use the
following for onclick:

<script language="JavaScript">
var lastRowSelected;
var lastRowSelectedColorUsed;
function prettyDG_changeBackColor(row)
{
var color = lastRowSelectedColorUsed;
lastRowSelectedColorUsed= row.style.backgroundColor;
row.style.backgroundColor = 'pink';
if (lastRowSelected != null)
lastRowSelected.backgroundColor = color;
lastRowSelected = row;
}
</script>

Eliyahu
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top