方法一:
可以在事件Datalist1_itemDataBound中这样写
鼠标悬停时改变背景颜色 #region 鼠标悬停时改变背景颜色
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
...{
if (e.Item.ItemType == ListItemType.Item)//如果当前行是正常行
...{
e.Item.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
#endregion
方法二:在循环的表格中添加onmousever和onmouseout事件设置一件变量e保存当前背景色
< asp:Datlist id = " Datalist1 " runat = " server " >
< ItemTemp >
< table onmouseover = " c=this.style.backgroundColor;this.style.backgroundColor='#6699ff' " onmouseout = " this.style.backgroundColor=c " >
</ talbe >
</ ItemTemp >
可以在事件Datalist1_itemDataBound中这样写
鼠标悬停时改变背景颜色 #region 鼠标悬停时改变背景颜色
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
...{
if (e.Item.ItemType == ListItemType.Item)//如果当前行是正常行
...{
e.Item.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
#endregion
方法二:在循环的表格中添加onmousever和onmouseout事件设置一件变量e保存当前背景色
< asp:Datlist id = " Datalist1 " runat = " server " >
< ItemTemp >
< table onmouseover = " c=this.style.backgroundColor;this.style.backgroundColor='#6699ff' " onmouseout = " this.style.backgroundColor=c " >
</ talbe >
</ ItemTemp >