By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,326 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,326 IT Pros & Developers. It's quick & easy.

GridView onmouseout problem

P: n/a


Hi,

I was using the datagrid and am now starting to use the gridview in
asp.net 2.0. I used to use the first below sub for when i would
mouseover a row - this highlighted the row but did not affect the
original colour of the datagrid on mouseout. My datagrid uses
alternating row colours. However when i try and amend the code for the
gridview - when i do a onmouseout all rows now go to a white backgound
and the alternating colours in the rows disappear.

The first sub shows the code that works in my datagrid and the second
sub shows the code that i have amended for my gridview so far but will
not work.

Can anyone see what i am doing wrong.

Thanks.

------------------------------------------------------------

Private Sub dgComments_ItemDataBound(ByVal sender As System.Object,
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dgComments.ItemDataBound

Dim dv As DataView = dgComments.DataSource
Dim dcCol As DataColumn
Dim dc As DataColumnCollection = dv.Table.Columns
Dim strID As String

For Each dcCol In dv.Table.Columns
If e.Item.ItemType = ListItemType.AlternatingItem Or
e.Item.ItemType = ListItemType.Item Then

strID = dgComments.DataKeys(e.Item.ItemIndex)

'To change the color of the row onMouseOver in the
Datagrid
e.Item.Attributes.Add("onmouseover",
"this.style.backgroundColor='#fef5d1'")
e.Item.Attributes.Add("onmouseout",
"this.style.backgroundColor='#ffffff'")

End If
Next

End Sub

---------------------------------------------------

Private Sub gvUser_ItemDataBound(ByVal sender As System.Object, ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs) Handles
gvUser.RowDataBound

Dim dv As Data.DataView = gvUser.DataSource
Dim dcCol As Data.DataColumn
Dim dc As Data.DataColumnCollection = dv.Table.Columns
Dim strID As String

For Each dcCol In dv.Table.Columns
If e.Row.RowType = ListItemType.AlternatingItem Or
e.Row.RowType = ListItemType.Item Then

strID =
gvUser.DataKeys(e.Row.DataItemIndex).Value.ToStrin g

'To change the color of the row onMouseOver in the
GridView
e.Row.Attributes.Add("onmouseover",
"this.style.backgroundColor='#fef5d1'")
e.Row.Attributes.Add("onmouseout",
"this.style.backgroundColor='#ffffff'")

End If
Next
End Sub

Mar 29 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.