gridview 中高亮显示  把原来的样式覆盖了呀,当我把鼠标移上去的时候是变了颜色但是鼠标移走变成我设置的颜色   我希望只是鼠标以上去就变色移走的话还是原来的颜色怎么搞呀!!! 

解决方案 »

  1.   

    分别设置onmouseover和onmouseout两种状态时的两种颜色
      

  2.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)   
      {   
      if (e.Row.RowType == DataControlRowType.DataRow) {   
      e.Row.Attributes.Add("onmouseover", "e=this.style.backgroundColor; this.style.backgroundColor='#cccccc'");   
      e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=e");   
      }   
      }
      

  3.   

     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
            {
              if (e.Row.RowType == DataControlRowType.DataRow) {   
                  e.Row.Attributes.Add("onmouseover", "e=this.style.backgroundColor; this.style.backgroundColor='#cccccc'");   
                  e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=e");   
              }   
            }
      

  4.   

    2楼的可行
    还可以用JS
    window.onload=function ()
        {
           var otr=document.body.getElementsByTagName("tr");
           for(var i=1;i<otr.length;i++)
           {
             otr[i].onmouseover=function ()
             {
                  this.style.backgroundColor="#c6f3b5";
             }
             otr[i].onmouseout=function ()
             {
                this.style.backgroundColor="#FFF";
             }
           }
        }
      

  5.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)   
      {   
      if (e.Row.RowType == DataControlRowType.DataRow) {   
      e.Row.Attributes.Add("onmouseover", "e=this.style.backgroundColor; this.style.backgroundColor='#cccccc'");   
      e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=e");   
      }   
      }   
    e.Row.Attributes.Add("onmouseover", "OverColor(tr" + e.Row.RowIndex.ToString() + ")");
      e.Row.Attributes.Add("onmouseout", "OutColor(tr" + e.Row.RowIndex.ToString() + ")");
    function OverColor(obj,tr)
      {
      currentcolor=tr.style.backgroundColor
      }
      function OutColor(tr)
      {
      tr.style.backgroundColor=currentcolor;
      }
      

  6.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#507CD1'");
                e.Row.Attributes["style"] = "Cursor:hand";
            }
        }
      

  7.   


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
    { if (e.Row.RowType == DataControlRowType.DataRow) 
       { e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''"); e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#507CD1'"); 
    } }
      

  8.   

    jQuery$(function(){
            var currentColor;
            $("table tr:has(td)").mouseover(function(){
                currentColor = $(this).css('background-color');
                $(this).css('background-color', '#42BAB6');
            });
            $("table tr:has(td)").mouseout(function(){
                $(this).css('background-color', currentColor);
            });
        });