您的位置:首页 > 其它

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

2007-02-06 14:49 477 查看
因为要经常使用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)");
}
}
颜色可以根据页面风格进行修改
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: