[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Datagrid onmouseover color change

Hi...I am working on a webpage using VB.net...i am using a data grid which displays data from SQL table. I am using <AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle> for different colors for alternate rows. Now I want to change the color of the row the mouse is over to some other color say Silver. I am doing this with the following code.
                If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
                    If Not IsNothing(e.Item.DataItem) Then
                        e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'")
                        e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")
                    End If
                End If
The problem is once the mouse leaves the row i am not able to get the previous color of the row. Can someone help me how to get the original color back. Thank You.
0
niki_kiran
Asked:
niki_kiran
  • 2
1 Solution
 
tusharashahCommented:
If you're using different color for Alternating Item then you need to Split your function like following

                If e.Item.ItemType = ListItemType.Item Then
                        e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'")
                        e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='white'")      'Normal Item Color
                End If
                If e.Item.ItemType = ListItemType.AlternatingItem Then
                        e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#DDEEFF'")
                        e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='Gainsboro'") 'Alternating Item Color
                End If

-tushar
0
 
niki_kiranAuthor Commented:
thanq
0
 
tusharashahCommented:
You are welcome :)

-tushar
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now