GridView邦定后,把鼠标移到一行上,怎样才能使这行变色?我实现的代码如下: protected void gvNewsList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType.ToString() == "DataRow")
{ e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='yellow',this.style.fontWeight=''");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white',this.style.fontWeight=''");
ImageButton btn = (ImageButton)(e.Row.FindControl("lnkbtnMod"));
if (btn != null)
{
string StrCatalogID = DataBinder.Eval(e.Row.DataItem, "CatalogID").ToString();
btn.Attributes.Add("onclick", "return redirect('" + StrCatalogID + "')");
}
} }
{
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"#color1\"");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"#color2\"");
)
{
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#000000'");
)
{
if (e.Row.RowType != DataControlRowType.Header)
{
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"" + e.Row.Style["BACKGROUND-COLOR"] + "\"");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"" + "#F0F8F7" + "\"");
}
}
<Columns>
<asp:BoundField DataField="ProductId" HeaderText="编号" SortExpression="ProductId" />
<asp:BoundField DataField="CategoryId" HeaderText="类别" SortExpression="ProductId" />
<asp:BoundField DataField="Name" HeaderText="名称" SortExpression="ProductId" />
<asp:CheckBoxField HeaderText="选择" />
<asp:HyperLinkField DataTextField="Name"
HeaderText="链接" DataNavigateUrlFields="ProductId" DataNavigateUrlFormatString="show.aspx?id={0}" />
</Columns>
<PagerSettings Mode="NumericFirstLast" />
</asp:GridView> protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.ToolTip = "显示的值";
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#000000'");
}
}在我自己电脑上试过,可以达到楼主的要求。
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C1D2EE'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
}
if (btn != null)
{
string StrCatalogID = DataBinder.Eval(e.Row.DataItem, "CatalogID").ToString();
btn.Attributes.Add("onclick", "return redirect('" + StrCatalogID + "')");
}
}
楼主,能否跟我讲解一下你这一段代码是干什么的哦?谢谢了~
是我的CSS中已设好了样式,无法用
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='yellow',this.style.fontWeight=''");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white',this.style.fontWeight=''");
来改变了,谢谢各位了!!