在GridView中如果想要在滑鼠移動時,滑鼠所指到的那一列會變色的話可以用JavaScript來達成
效果就像下面的圖所示,滑鼠所指到的那一列會變成亮黃色,移開後再還原成原本的顏色
以下為程式碼片段,於RowDataBound的事件中綁定JavaScript到Row中
Private Sub GridView1_RowDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles GridView1.RowDataBound
'滑鼠移入移出效果。
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;")
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor; this.style.backgroundColor='#ffff40';")
End If
End Sub

