天天看點

ASP.NET2.0下為GridView添加滑鼠滑過(onmouseover、onmouseout)的效果

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

   }

轉載于:https://www.cnblogs.com/gzfteam/archive/2012/11/08/2761699.html