我正在尝试使所有行都有悬停背景,但标题行除外。
任何提示?
我有BoundFields,TemplateField和CommandField。
答案 0 :(得分:2)
答案 1 :(得分: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>
答案 2 :(得分: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';");
}
}
您还可以使悬停效果保持交替行的颜色。