天天看點

Asp.Net中GridView加入滑鼠滑過的高亮效果和單擊行顔色改變

下面是Asp.Net中GridView滑鼠滑過的樣式改變和單擊時候樣式改變的代碼:

//加入滑鼠滑過的高亮效果

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

繼續閱讀