您的位置:首页 > 其它

Gridview相关颜色显示(满足特定数据要求的颜色显示,鼠标事件颜色显示)

2007-10-30 12:49 495 查看
我们可以在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='';");

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: