472,794 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

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
1 6592
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bryan Masephol | last post by:
Hi All I got a datagrid and a ComboBox on a form. I populate the combobox with years for all the data avaiable. When the user chooses a year the datagrid is populated with the specific years...
0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
2
by: Serge | last post by:
Hi, in my windows.forms application I have added a goupBox control to my windows.form. Now I want to know the x,y-position from the mouse cursor when I click on the groupBox. The strange thing...
2
by: Deepesh | last post by:
Good day, I have a specific case of the DataGrid in my solution which is causing the ItemCommand Event Not Firing. So I'm creating a "Skinnable" set of controls. I seperate the actual ASCX file...
6
by: jcrouse | last post by:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax. I don't really understand the event. Where it...
1
by: Andy | last post by:
Hi all, I'm a beginner. I have a problem. In my datagrid i have read only data grid. I written code to delete a row by using delete key in keydown event of datagrid. But this event is not always...
5
by: Nick | last post by:
Hey guys, I have 2 events on a windows forms datagrid, the mouse move as well as the double click events. What's happening is that when I double click on a row in the grid, the mouse move event...
3
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data...
3
by: Gidi | last post by:
Hi, I've a dataGrid, and When I click with the mouse on one of it's header the DataGrid_Click event is called. I don't have problem with the event, but strange things happen to the dataGrid...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.