<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" Width="100%" CssClass="gridviewStlye" OnRowDataBound="GridView_RowDataBound" >
样式表中
.gridviewStlye{ border:1px solid #ccc; }
.gridviewStlye td{ background:#fff; border:1px solid #c0de98;}
.gridviewStlye th{background-image: url(../images/tab_14.gif); height:18px; border:1px solid #c0de98; }想让鼠标移上去有变化
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
//鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
}但是这样没有变化 ,把gridview的样式CssClass="gridviewStlye" 去了就可以了,为什么会这样呢?
样式表中
.gridviewStlye{ border:1px solid #ccc; }
.gridviewStlye td{ background:#fff; border:1px solid #c0de98;}
.gridviewStlye th{background-image: url(../images/tab_14.gif); height:18px; border:1px solid #c0de98; }想让鼠标移上去有变化
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
//鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
}但是这样没有变化 ,把gridview的样式CssClass="gridviewStlye" 去了就可以了,为什么会这样呢?
td不能设背景色
<tr onmouseover="this.style.backgroundColor='#E6F5FA'" onmouseout="this.style.backgroundColor='#FFFFFF'" style="cusor:hand">是在tr中的