- 您可以參考下列作法:
- Code Snippet protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- e.Row.Attributes.Add("onMouseOver", "SetNewColor(this);");
- e.Row.Attributes.Add("onMouseOut", "SetOldColor(this);");
- }
- 然後Javascript可以這樣設定:
- Code Snippet var _oldColor;
- function SetNewColor(source)
- {
- _oldColor = source.style.backgroundColor;
- source.style.backgroundColor = '#EEFE96'; //這是要變化的顏色
- }
- function SetOldColor(source)
- {
- source.style.backgroundColor = _oldColor;
- }
或者是这里的做法:
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
- 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='';");
- //单击行改变行背景颜色
- e.Row.Attributes.Add("onclick","this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");
- }