因为要经常使用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)");
            }
        }
     颜色可以根据页面风格进行修改
posted on 2007-02-06 14:49  xiazhaoxia  阅读(447)  评论(0编辑  收藏  举报