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

在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
");

  }
  }

转载于:https://www.cnblogs.com/conquer/archive/2006/11/08/554388.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值