Solved

Datagrid - how to highlight rows with mouseover

Posted on 2003-10-22
3
361 Views
Last Modified: 2010-04-16
Anyone know how to use the onmouseover event to get the rows to highlight in a datagrid?  
0
Comment
Question by:marmar111
3 Comments
 
LVL 1

Expert Comment

by:jlach
ID: 9600866
The way to do this is prolly to capture the mouse move event on the data grid, then get the location of the mouse relative to the grid, then go ahead and write a routine to get the row that is at the location of the mouse...
0
 
LVL 8

Expert Comment

by:gregasm
ID: 10464972
Try to capture the onMouseOver event of the DataGridTextBoxColumn.
0
 
LVL 3

Accepted Solution

by:
nhewitt21 earned 20 total points
ID: 11591533
I used the OnItemCreated in my datagrid to do this for one of my webprojects:

For example:
OnItemCreated="List_DataGrid_ItemCreated"

Then in your codebehind (C#):
protected void ListNews_DataGrid_ItemCreated(Object sender, DataGridItemEventArgs e)
{
      DataGridItem myItem = e.Item;
      switch (myItem.ItemType)
      {
            case ListItemType.Item:
                  myItem.Attributes.Add("onmouseover", "this.style.backgroundColor=\"#FFD3D3\"");
                  myItem.Attributes.Add("onmouseout", "this.style.backgroundColor=\"#D9D9D9\"");
                  break;
            case ListItemType.AlternatingItem:
                  myItem.Attributes.Add("onmouseover", "this.style.backgroundColor=\"#FFD3D3\"");
                  myItem.Attributes.Add("onmouseout", "this.style.backgroundColor=\"#E9E9E9\"");
                  break;
            default:
                  break;
      }
}

Job Done.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why, and when, to use Windows Workflow 1 32
C# Connection String for Oracle database is not working 22 92
What .NET website keeps me current? 9 57
Problem to error 4 46
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now