I want to use repeater to populate anchors and links to that anchors dynamically.
I know for statistic case we can do this:
<a href="#anchor">Link Text</a>
and the anchor :
<a name="anchor"></a>
Now, to create the link dynamically I use:
<asp:Repeater ID="LinkRepeater" runat="server">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" class="TopMenuBarLink" NavigateUrl='<%# Eval("Link")%>'>
<%# Eval("Title")%>
</asp:HyperLink>
</ItemTemplate>
</asp:Repeater>
But when I run the program, on the website, use inspect element I get this for the links:
<a id="_ctl0_viewCompanies_LinkRepeater_HyperLink1_0" class="TopMenuBarLink" href="Mypath/MyAnchor">My title text</a>
How do I get it in the right form:
<a id="_ctl0_viewCompanies_LinkRepeater_HyperLink1_0" class="TopMenuBarLink" href="#MyAnchor">My title text</a>
Do you have a specific reason that you're using a server control for your hyperlink? why not use a normal anchor element.
<asp:Repeater ID="LinkRepeater" runat="server">
<ItemTemplate>
<a class="TopMenuBarLink" href='#<%# Eval("Link")%>'>
<%# Eval("Title")%>
</a>
</ItemTemplate>
</asp:Repeater>
我会尝试这样做(在ASP.Net代码括号之前添加#符号):
NavigateUrl='#<%# Eval("Link")%>'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.