我在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"> · <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>
<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"> · <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>
解决方案 »
- 关于SQL插入多条记录的问题
- discuz整合问题,知道的都进来看看。
- 日期格式问题(急)
- 关于如何在服务端获取同一页面中客户端隐藏控件的值的问题
- 请教一个FreeTextBox 1.6.3 中文版的问题!
- 最后70分,问最后一个问题!高手来
- 一个DataGrid界面样式运用的简单问题
- 在IE中怎样调用本地打印机打印,救急,在线等
- 控件SqlDataSource连不上库, 总提示错误, 大家帮忙看看!!
- 为何LABEL不显示?
- asp.net前台页面中有vbscript和jscript,如何在jscript中调用vbscript的方法?
- 查询access数据库时间字段 一个月缺少几天,并记录缺少的天数
<asp:HyperLink CssClass=""></asp:HyperLink>或者你再后台写个方法return css名称。
前台class <%=Css()%>
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')"); }
}
写在后台吧
e.Row.Attributes.Add("onMouseOver", "this.style.text-decoration='underline'");
e.Row.Attributes.Add("onMouseOut", "this.style.text-decoration=none;");