DataGrid中实现鼠标指向行背景变化。
效果如孟子的网站:http://dotnet.aspx.cc/ 问题点数:20、回复次数:4Top
1 楼jyk(今天由我来写的代码,明天就让程序自己完成!喜欢编程。和气生财。共同提高。共同进步!)回复于 2005-05-17 20:09:17 得分 1
你去看他的代码不就行了吗?
Top
2 楼cm8983(思远)回复于 2005-05-17 20:19:09 得分 7
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 subTop
3 楼FoxLinn(业余编程爱好者)回复于 2005-05-17 21:12:40 得分 8
后台:
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">
Top
4 楼joeweng(蓝天天蓝)回复于 2005-05-17 21:20:09 得分 4
设置onmouseover 和 onmouseout 时改变CSS样式
e.Item.Attributes.Add("onmouseout", "this.CSSCLASS = 'CSS'");
Top




