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';");
}