我们可以在Gridview的RowDataBound事件中来处理相关颜色的显示! 很简单,看代码就能明白!
 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='';");
           
        }
    }
    
posted on 2007-10-30 12:49  都说大哥好  阅读(625)  评论(0编辑  收藏  举报