在gridview里面
怎么达到一个效果
就是鼠标经过行的时候,行的颜色会变,鼠标离开,颜色恢复默认,不需要鼠标点击。
是加鼠标事件吗?
在asp里面,鼠标事件加在<tr>里面
在.net里面应该加在哪里?
请大家指点,谢谢。

解决方案 »

  1.   

    这个网上一堆堆  lz 给分吧。
     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='LightSkyBlue',this.style.fontWeight='';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            }    }
      

  2.   

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

  3.   

    http://tech.163.com/06/1010/11/2T2Q12E00009215D.html
    这个视频教程上说的很详细.来分吧.
      

  4.   

    protected   void   GridView_RowDataBound(object   sender,GridViewRowEventArgs   e) 

        if(e.Row.RowType   ==   DataContrelRowType.DataRow) 
          { 
            e.Row.Attributes.Add("onmouseover","this.style.backgroundColor='#EEEEEE';"); 
            e.Row.Attributes.Add("onmouseout","this.style.backgroundColor='#FFFFFF';"); 
          } 
    }
    用这个..
      

  5.   

    5楼的和2楼的一样
     if(e.Row.RowType       ==       DataContrelRowType.DataRow) 
    提示 当前上下文中不存在名称“DataContrelRowType”
      

  6.   

    DataContrelRowType在System.Web.UI.WebControls 下
      

  7.   

    谢谢大家,效果已经出来了
    还有最后一点,鼠标移走的时候,行颜色能不能不指定,而是回复默认。如果必须指定回复成某个颜色的话,
    gridview 有个交替行,两个行的默认颜色不一样,protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#afd6f5';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#F1F9FE';");
            }
        }应该怎么修改?
      

  8.   

    当然可以,把e.Row.Attributes.Add("onmouseout",   "this.style.backgroundColor='#F1F9FE';")去掉.
      

  9.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#afd6f5';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor;");
            }
        } 得到我要的效果了,谢谢大家了。