您的位置:首页 > 其它

鼠标移动DataGrid控件某行改变该行的背景

2006-11-08 17:35 423 查看
在DataGrid控件的数据项的Attributes属性为数据项添加Javascript脚本即可
(1) 触发onmouseover事件时,执行如下代码设置当前DataGrid项的背景色
thiscolor = this.style.backgroundColor,this.style.backgroundColor='#ddf3ff'

(2) 当触发onmouseout事件时,执行如下代码还原前面的背景色
this.style.backgroundColor = thiscolor

在DataGrid控件的ItemDataBound事件

private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//如果当前项不为空
if(e.Item.ItemIndex != -1)
{
//取得当前索引值加1,因为索引是从0开始,给DataGrid自动编号
int orderID = e.Item.ItemIndex +1;
e.Item.Cells[1].Text = orderID.ToString();

}
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","thiscolor = this.style.backgroundColor,this.style.backgroundColor='#ddf3ff'
");
e.Item.Attributes.Add("onmouseout"," this.style.backgroundColor = thiscolor
");

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐