现在的位置: 首页 > 综合 > 正文

GridView行添加mouseout,onclick,mouseover事件

2012年12月15日 ⁄ 综合 ⁄ 共 777字 ⁄ 字号 评论关闭
HTML:
<script type="text/javascript"> 
  var oldrow=null; 
  var currentcolor=null; 
  var oldcolor=null; 
  function selectx(row) 
  { 
  if(oldrow!=null) 
  { 
  oldrow.style.backgroundColor=oldcolor; 
  } 
  row.style.backgroundColor='#99ccff'; 
  oldrow=row; 
  oldcolor = currentcolor;
  } 
</script> 

.cs:
  
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {

  if (e.Row.RowType == DataControlRowType.DataRow)
  {
  e.Row.Attributes.Add("onmouseover", "if(this!=oldrow){currentcolor=this.style.backgroundColor;this.style.backgroundColor='PeachPuff',this.style.fontWeight='';}");
  e.Row.Attributes.Add("onmouseout", "if(this!=oldrow){this.style.backgroundColor=currentcolor;this.style.fontWeight='';}");
  e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");
  } 
  }

抱歉!评论已关闭.