[英]how to bind dropdownlist which is inside the itemtemplate field of datalist control
[英]Not able to bind database field value properly to anchor tag inside datalist control
我在数据列表控件中有锚标记。 我在代码后面绑定DataList,它工作正常。 但问题是我在数据库中保留了链接(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://
否则它将无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.