Public Sub DataGrid_MouseOn(ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) '定义鼠标 If (e.Item.ItemIndex > -1) Then e.Item.Attributes.Add("onmouseover", "this.setAttribute('BKC',this.style.backgroundColor); this.style.cursor='hand';this.style.backgroundColor='#dddddd'") e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=this.getAttribute('BKC');") End If End Sub用法: Private Sub myDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles myDataGrid.ItemDataBound DataGrid_MouseOn(e) end sub
后台: Public Sub dgList_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then '--- 增加鼠标效果 OnMouseOver / OnMouseOut e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'") e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#eeeeff'") '--- 改变特定 Cell (Column) 的鼠标式样(Or you may do it for a whole Row of DataGrid :) e.Item.Cells(1).Style("cursor") = "hand" End If End Sub前台: <asp:datagrid id="DataGrid1" runat="server" backcolor="#eeeeff" autogeneratecolumns="False" bordercolor="#0033FF" headerstyle-backcolor="#99ccff" font-size="8pt" headerstyle-horizontalalign="Center" onitemdatabound="dgList_ItemDataBound">
'定义鼠标
If (e.Item.ItemIndex > -1) Then
e.Item.Attributes.Add("onmouseover", "this.setAttribute('BKC',this.style.backgroundColor); this.style.cursor='hand';this.style.backgroundColor='#dddddd'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=this.getAttribute('BKC');")
End If
End Sub用法: Private Sub myDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles myDataGrid.ItemDataBound
DataGrid_MouseOn(e)
end sub
Public Sub dgList_ItemDataBound(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
'--- 增加鼠标效果 OnMouseOver / OnMouseOut
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='Silver'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#eeeeff'")
'--- 改变特定 Cell (Column) 的鼠标式样(Or you may do it for a whole Row of DataGrid :)
e.Item.Cells(1).Style("cursor") = "hand"
End If
End Sub前台:
<asp:datagrid id="DataGrid1" runat="server" backcolor="#eeeeff" autogeneratecolumns="False" bordercolor="#0033FF"
headerstyle-backcolor="#99ccff" font-size="8pt" headerstyle-horizontalalign="Center" onitemdatabound="dgList_ItemDataBound">