如题
我参考 网上的代码 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor= '#0054E3 ' ");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c; ");
}
}为何会没有效果呢?
求解释
我参考 网上的代码 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor= '#0054E3 ' ");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c; ");
}
}为何会没有效果呢?
求解释
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridViewCostBill_RowDataBound">
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FBEACC'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
onrowdatabound="GridView1_RowDataBound" DataKeyNames="typeGuid"
onrowdeleting="GridView1_RowDeleting" Height="122px" Width="783px">
<Columns>
<asp:BoundField DataField="typeGuid" />
<asp:BoundField DataField="typeName" HeaderText="类别名称" />
<asp:BoundField DataField="typeId" HeaderText="类别编号" />
<asp:TemplateField>
<ItemTemplate>
<a href="managerAddEditType.aspx?typeGuid=<%# Eval("typeGuid") %>&state=Edit">编辑</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="Delete" Text="删除" OnClientClick="return confirm('确认删除吗?')"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle BorderColor="Red" BorderWidth="3px" />
</asp:GridView>这个是前台的代码
protected void gvFromSalon_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType != DataControlRowType.DataRow)
{
return;
}
e.Row.Attributes.Add("onmouseover", "if(this!=oldrow){currentcolor=this.style.backgroundColor;this.style.backgroundColor='PeachPuff',this.style.fontWeight='';}");
e.Row.Attributes.Add("onmouseout", "if(this!=oldrow){this.style.backgroundColor=currentcolor;this.style.fontWeight='';}");
e.Row.Attributes.Add("onclick", e.Row.ClientID.ToString() + ".checked=true;selectx(this)");
}
js
<script type="text/javascript">
var oldrow=null;
var currentcolor=null;
var oldcolor=null;
function selectx(row)
{
if(oldrow!=null)
{
oldrow.style.backgroundColor=oldcolor;
}
row.style.backgroundColor='#99ccff';
oldrow=row;
oldcolor = currentcolor;
}
</script>
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor= '#0054E3 ' ");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c; ");
}
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Attributes.Add("style", "display:none"); }
} 这个是全部的RowDataBound代码
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Attributes.Add("onMouseOver", "MouseOver(this)");
e.Row.Attributes.Add("onMouseOut", "MouseOut(this)");
}
var color;function MouseOver(Element)
{
color = Element.style.backgroundColor;
Element.style.backgroundColor = "#b7c4e2";
Element.style.cursor = "hand";
}function MouseOut(Element)
{
Element.style.backgroundColor = color;
Element.style.cursor = "default";
}
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=white; ");