GridView控件中添加“移动鼠标行背景变色”效果
大家帮忙看下一个问题,我在gridview控件中添加一个行背景色变换。但是现在第一行的颜色总是不能变,大家看下我的代码,看问题出在哪里。
<asp:GridView ID= "GridView1 " runat= "server " AllowPaging= "True " AllowSorting= "True "
AutoGenerateColumns= "False " DataKeyNames= "id " DataSourceID= "SqlDataSource1 " OnRowDataBound= "GridView1_RowDataBound ">
Inherits System.Web.UI.Page
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Dim i As Integer = 0
Do While i < GridView1.Rows.Count
If (e.Row.RowType = DataControlRowType.DataRow) Then
e.Row.Attributes.Add( "OnMouseOver ", "this.style.backgroundColor= '#ff0000 ' ")
e.Row.Attributes.Add( "OnMouseOut ", "this.style.backgroundColor= ' '; ")
Label1.Text = e.Row.ToString() & "| " & " <br/> "
End If
i = i + 1
Loop
End Sub
------解决方案--------------------protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//鼠标略过行改变行颜色
e.Row.Attributes.Add( "onmouseover ", "c=style.backgroundColor;style.backgroundColor= 'skyblue '; ");
e.Row.Attributes.Add( "onmouseout ", "style.backgroundColor=c ");
}
#endregion