读书人

GridView控件中添加“移动鼠标行背景变

发布时间: 2012-02-29 16:44:10 作者: rapoo

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

读书人网 >asp.net

热点推荐