I have a list of strings where by each string is a url to a pdf document. All I want to do is cycle through this list and display each url as a hyperlink on my page. I've seen this done before in MVC where the collection is made开发者_如何学Python avaliable to the view and you can just do a foreach etc etc but I don't know how to do it on a normal asp.net page...
Any help appreciated, cheers!
You could create the links using an ASP repeater on the page and bind your List to it.
Page:
<asp:Repeater id="repLinks" runat="server">
<ItemTemplate>
<asp:HyperLink runat="server" NavigateUrl='<%# Container.DataItem.ToString() %>' Text="LinkText" />
</ItemTemplate>
</asp:Repeater>
Code-behind:
List<string> lLinks = new List<string>();
//Define your list contents here
repLinks.DataSource = lLinks;
repLinks.DataBind();
Something like that should do the trick.
<%
foreach(var url in Urls)
{
%><a href="<%=url%>"><%=url%></a><%
}
%>
精彩评论