我在asp.net中用VB写的如下:'Private Sub dgrdRecord_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgrdRecord.ItemDataBound
' Dim c As Object
' If e.Item.ItemType = ListItemType.Item Then
' e.Item.Attributes.Add("onmouseover", "dgrdrecord.ItemStyle.BackColor=blue ")
' e.Item.Attributes.Add("onmouseout", " dgrdrecord.ItemStyle.BackColor =''")
' End If
'End Sub但执行的时候,不知道为什么没反应,我觉得是ADD中第二个参数模式有问题,想请教更改一下?谢谢!
' Dim c As Object
' If e.Item.ItemType = ListItemType.Item Then
' e.Item.Attributes.Add("onmouseover", "dgrdrecord.ItemStyle.BackColor=blue ")
' e.Item.Attributes.Add("onmouseout", " dgrdrecord.ItemStyle.BackColor =''")
' End If
'End Sub但执行的时候,不知道为什么没反应,我觉得是ADD中第二个参数模式有问题,想请教更改一下?谢谢!
7{
8 if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
9 {
10 e.Item.Attributes.Add("onmouseover","this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#C8F7FF'");
11 e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");
12 for (int i=0;i<DataGrid1.Columns.Count;i++)
13 {
14 e.Item.Cells[i].Attributes.Add("onmouseover","this.oldcolor=this.style.backgroundColor;this.style.backgroundColor='#99ccff'");
15 e.Item.Cells[i].Attributes.Add("onmouseout", "this.style.backgroundColor=this.oldcolor");
16 }
17 }
18}
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#C0C0FF'")
'当鼠标移走时还原该行的背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor")
不要用dgrdrecord.ItemStyle.BackColor
^o^
认得,那个就是datagrid控件
但前面e对象没有row属性还是用的item。谢谢了!怎么结贴呢?
{
if(e.Item.ItemType==ListItemType.AlternatingItem |e.Item.ItemType==ListItemType.Item)
{
e.Item.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#ffff66'");
//添加自定义属性,当鼠标移走时还原该行的背景色
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=currentcolor");
}
}
{
if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem )
{
//添加鼠标移过行时背景变色效果
e.Item.Attributes[ "onmouseover" ] = "rowColor = this.style.backgroundColor;this.style.backgroundColor = '#FFFF99'" ;
e.Item.Attributes[ "onmouseout" ] = "this.style.backgroundColor = rowColor" ;
}
base.OnItemCreated( e ) ;
}