[英]c# how to set the styling of a gridview text field to 2 options: with hyperlink and without
I have a code for a gridview feild that displays a title, and evaluates a hyperlink (link) in a way that if there is a value in the link, that title will be clickable and the title will redirect you to the link.. as followed: 我有一个显示标题的gridview feild代码,并以一种方式评估超链接(链接),如果链接中有值,该标题将是可点击的,标题将重定向到链接.. as其次:
<asp:TemplateField HeaderText="Title" SortExpression="Title" ControlStyle-ForeColor="Black">
<ItemTemplate >
<asp:HyperLink ID="Title" runat="server" Text='<%# Bind("Title") %>' NavigateUrl='<%# Eval("link") %>' ></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
The code is working fine, but the title is currently black. 代码工作正常,但标题目前是黑色的。 I need to style the title in a way that if there is a link, it will be blue and undelined, else it will be black.
我需要设置标题的样式,如果有链接,它将是蓝色和未标记,否则它将是黑色。
I'm using C#/aspx in here. 我在这里使用C#/ aspx。
Any idea? 任何想法?
尝试这个
<asp:HyperLink ID="Title" runat="server" Text='<%# Bind("Title") %>' NavigateUrl='<%# Eval("link") %>' style='<%# Eval("link").ToString()!=""? "text-decoration:underline;color:Blue;":""%>'></asp:HyperLink>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.