在RowDataBound事件里写
Dim i As Int32 For i = 0 To GridView1.Rows.Count
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'")
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c")
End If
Next
当然,也可更简单些:
If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'")
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'")
End If