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

解决方案 »

  1.   

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"#color1\"");
    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"#color2\"");
    )
      

  2.   

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#000000'");
    )
      

  3.   

    代码没问题~ 问题在于这段代码执行了没? 有没有<asp:GridView ID="gvNewsList" runat="server" OnRowDataBound="gvNewsList_RowDataBound">
      

  4.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       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" + "\"");
       }
    }
      

  5.   

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" SkinID="GridViewSkin" Width="100%" AllowPaging="True" AllowSorting="True" OnRowCreated="GridView1_RowCreated" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound" >
                                <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'");
            }
        }在我自己电脑上试过,可以达到楼主的要求。
      

  6.   

    放到GridView1_RowCreated事件里试试
      

  7.   

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" OnRowDataBound="GridView1_RowDataBound" >
      

  8.   

    if (e.Row.RowType==DataControlRowType.DataRow)
                {
                    e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#C1D2EE'");
                    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
    }
      

  9.   

    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 + "')");
                }
            }
    楼主,能否跟我讲解一下你这一段代码是干什么的哦?谢谢了~
      

  10.   

    谢谢各位,我已经解决了
    是我的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=''");
    来改变了,谢谢各位了!!