protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//將滿足特定條件的行標為高亮
if (e.Row.RowType == DataControlRowType.DataRow)//判定當前的行是否屬於datarow型別的行
{
int money = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "MONEY"));//取當前行的列值
if (money == 77)
e.Row.BackColor = Color.Red;
//string customer = (string)DataBinder.Eval(e.Row.DataItem, "CUSTOMER");
string customer = DataBinder.Eval(e.Row.DataItem, "CUSTOMER").ToString();
if (customer == "sdf")
e.Row.BackColor = Color.Red;
}
//加入滑鼠滑過的高亮效果
if (e.Row.RowType == DataControlRowType.DataRow)//判定當前的行是否屬於datarow型別的行
{
//當滑鼠放上去的時候 先儲存當前行的背景顏色 並給附一顏色
e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow',this.style.fontWeight='';");
//當滑鼠離開的時候 將背景顏色還原的以前的顏色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
}
//單擊行改變行背景顏色
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick","this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
}