Gridview相关颜色显示(满足特定数据要求的颜色显示,高亮显示)

来源:互联网 发布:怎样写好钢笔字 知乎 编辑:程序博客网 时间:2024/05/16 00:30

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
if (e.Row.RowType == DataControlRowType.DataRow)
        {
           
string str = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "UserName"));
            
//满足特定要求的数据显示不同的颜色
            if (str=="duoduo")
            {
                e.Row.BackColor 
= System.Drawing.Color.Beige;
            }  
            e.Row.Cells[
1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";           
            
//鼠标经过或者离开时候显示不同的颜色
            e.Row.Attributes.Add("onmouseover""currentcolor=this.style.backgroundColor;this.style.backgroundColor='red',this.style.fontWeight='';");
            
//当鼠标离开的时候 将背景颜色还原的以前的颜色
            e.Row.Attributes.Add("onmouseout""this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
           
        }
    }

原创粉丝点击