我在数据列表控件中有锚标记。我正在隐藏代码中绑定数据列表,它工作正常。但问题是我在数据库中保留了链接(url)字段。要将用户重定向到此 URL,我正在将锚标记与此字段绑定。但它没有给出正确的地址。它在开始时将我的本地主机(网站地址)附加到它,这是我不想要的。我的代码如下:
<asp:DataList ID="dlPost" runat="server" RepeatColumns="1" RepeatDirection="Vertical"
Width="755px">
<ItemTemplate>
<article class="post medium">
<div class="medium-content">
<header class="meta">
<h2> <a href ="#"><asp:Label ID="lblTitle" runat="server" Text='<%#Eval("PostTitle") %>' style="font-weight:600; color:#444444;"></asp:Label></a></h2>
</header>
<p> <asp:Label ID="lblPost" runat="server" Text='<%#Eval("Post") %>'></asp:Label></p>
<a href='<%#Eval("PostLink") %>' class="button color">Job Link</a>
</div>
</article>
<div class="line"></div>
</ItemTemplate>
</asp:DataList>
下面是我尝试将数据库的 url 字段与锚标记绑定的部分。
<a href='<%#Eval("PostLink") %>' class="button color">Job Link</a>
因此,如果数据库的 Poslink 字段包含 www.abc.com
,它会将其重定向到 http://localhost:54636/CKWeb/www.abc.com
而不是www.abc.com
你应该使用http://
来使其工作。您的动态 href 应使用
'<%# string.Format("http://{0}",Eval("link"))%>'
使用上述内容可确保您的链接不包含http://
否则将无法正常工作。