467,888 Members | 1,387 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,888 developers. It's quick & easy.

Datagrid control to change the row color on Mouse click event

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
Nov 19 '05 #1
  • viewed: 6411
Share:
1 Reply
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

"karunakar" <ka***********@stcroixsystems.com> wrote in message
news:OO**************@TK2MSFTNGP12.phx.gbl...
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

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bryan Masephol | last post: by
reply views Thread by Emerson | last post: by
2 posts views Thread by Deepesh | last post: by
3 posts views Thread by Gidi | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.