datagrid小tip(一):鼠标的移动和点击变色

    因为要经常使用datagrid,所以讲在网上搜到的一些美化和优化datagrid代码整理一下放到这里,备忘.
    1.datagrid的行对鼠标的移动和点击变色的响应事件.
       前台
<script language="javascript">
        
function aa(e)
        {
            
for(var i=1;i<DataGrid1.rows.length; i++)
            {
                
if(DataGrid1.rows[i].style.backgroundColor == "#f6ab00")
                {
                    DataGrid1.rows[i].style.backgroundColor 
= "";
                }
            }
            
if(e.style.backgroundColor != "#f6ab00")
            {
                e.style.backgroundColor 
= "#f6ab00";
            }
        }
        
</script>

     后台
        private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            
if(e.Item.ItemType != ListItemType.Header)
            {
                e.Item.Attributes.Add(
"onmouseover","if(this.style.backgroundColor != '#f6ab00') this.style.backgroundColor='#f6f6f6'");                
                e.Item.Attributes.Add(
"onmouseout","if(this.style.backgroundColor != '#f6ab00') this.style.backgroundColor=''");
                e.Item.Attributes.Add(
"onclick","aa(this)");
            }
        }
     颜色可以根据页面风格进行修改

转载于:https://www.cnblogs.com/xiazhaoxia/archive/2007/02/06/642264.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值