如题
我参考 网上的代码         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; ");
            }
        }为何会没有效果呢? 
求解释

解决方案 »

  1.   

    RowDataBound这个事件注册了吗?
      

  2.   


     <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");
        }
    }
      

  3.   

     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                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>这个是前台的代码 
      

  4.   

    .cs绑定的时候
    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>
      

  5.   

    我注册过了  还写了个隐藏第一列的代码 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; ");
                }
                if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
                {
                    e.Row.Cells[0].Attributes.Add("style", "display:none");            }
               
            } 这个是全部的RowDataBound代码
      

  6.   


            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";
    }
      

  7.   

    你调试的时候,RowDataBound里面的代码运行吗
      

  8.   

      e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor= '#0054E3 '");
      e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=white; ");