2009-06-30 22 views
0

我试图让所有的行都有一个悬停的背景,除了标题行。ASP.NET Gridview - 如何创建所有行,但标题行有悬停效果?

任何提示?

我有BoundFields,TemplateField和CommandField。

+0

你是如何实现悬停效果客户端来实现? – TheVillageIdiot 2009-06-30 07:18:19

+0

那么,我现在还没有真正实施它。 作为一个临时的解决方案,我已经得到了我的GridView的CSS样式如下: .MyClass TR:悬停{ 背景色:#BBBBBB } – 2009-06-30 07:21:41

回答

1

这是怎么可以做到

<asp:GridView... OnRowCreated="GvListingReport_RowCreated" /> 

并在代码

 public void GvListingReport_RowCreated(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#DDDDDD';this.style.cursor='hand'"); 

      ListingRecord record = e.Row.DataItem as ListingRecord; 
      if (record != null) 
      { 
       e.Row.Attributes.Add("onclick", "javascript:MM_openBrWindow('" + url + "','dec','scrollbars=yes,resizable=yes')"); 
      } 

      e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF';"); 
     } 
    } 

您也可以悬停效果维持交替行的颜色。

2

这可以使用jQuery

<script type="text/javascript" src="path/to/jquery"></script> 
<script type="text/javascript"> 
     $(document).ready(function(){ 
      $("#<%= grid.ClientID%> tr").not("tr:first-child").hover(
      function(){$(this).addClass("OnMouseOverClass");},//mouse-over 
      function(){$(this).removeClass("OnMouseOutClass");});//mouse-out 
     }); 
</script>