我在GridView中绑定了字段,然后设置超链接,我想改变链接的样式和颜色,在<head>中有如下代码:
<style type="text/css">
        a:link
        {
            color: #000000;
            text-decoration: none;
        }
        a:visited
        {
            text-decoration: none;
            color: #0000FF;
        }
        a:hover
        {
            text-decoration: underline;
            color: #FF0000;
        }
        a:active
        {
            text-decoration: none;
        }
        -- body
        {
            margin-left: auto;
            margin-right: auto;
        }
        -- ></style>
但是,实际一点效果都没有,鼠标悬停在链接上的时候没有出现下划线,颜色也不改变,GridView部分如下:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                            DataSourceID="SqlDataSource1" ForeColor="Black" ShowHeader="False"
                            Width="250px" HorizontalAlign="Left">
                            <RowStyle />
                            <RowStyle HorizontalAlign="Left" />
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" rules="none">
                                            <td style="line-height: 22px;" height="30">
                                                <font size="3"> &nbsp;&middot; &nbsp;<a href='<%# "newscontent.aspx?newsID="+Eval("ID")%>' target="_blank"
                                                    title='<%#Eval("ArtTitle") %>'>
                                                    <%# StringTruncat(Eval("ArtTitle").ToString(), 20, "...")%>
                                                </a></font>
                                            </td>
                                        </table>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>

解决方案 »

  1.   


    <asp:HyperLink CssClass=""></asp:HyperLink>或者你再后台写个方法return css名称。
    前台class <%=Css()%>
      

  2.   


       protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                HyperLink hk = e.Row.FindControl("HyperLink1") as HyperLink;
                string url = "AdminUpdate.aspx?id=" + hk.Text +"&hid="+HiddenField1.Value+"&hid2="+HiddenField2.Value;
                hk.NavigateUrl = url;
                if (e.Row.RowType == DataControlRowType.Header)
                    return;
                e.Row.Attributes.Add("onMouseOver", "color=this.style.backgroundColor;this.style.backgroundColor='#F3F8FF'");
                e.Row.Attributes.Add("onMouseOut", "this.style.backgroundColor=color;");
                e.Row.Attributes["style"] = "Cursor:hand";
                e.Row.Attributes.Add("OnDblClick", "window.open('" + url + "','', 'alwaysRaised=1,dependent=1,resizable=0,scrollbars,width=800,height=600')");        }
           
        }
    写在后台吧
      

  3.   


            e.Row.Attributes.Add("onMouseOver", "this.style.text-decoration='underline'");
                e.Row.Attributes.Add("onMouseOut", "this.style.text-decoration=none;");
      

  4.   

    自己控制样式  onmouseover和onmouseout事件