I use a ListView to display (funnily enough) a list of data, including a hyperlink. Here is my item template (ascx file):
<a href='<%# DataBinder.Eval(CType(Container, ListViewDataItem).DataItem, "ID","/Pages/Image.aspx?id={0}").ToString()%>'
title='View <%# DataBinder.Eval(CType(Container, ListViewDataItem).DataItem, "Title")%>'>
<%# DataBinder.Eval(CType(Container, ListViewDataItem).DataItem, "CardNo")%> -
<%# DataBinder.Eval(CType(Container, ListViewDataItem).DataItem, "Title")%></a>
I'm having problems with the link resolving correctly as this same template is re-used multiple times across the project and fails for pages in a subfolder. I guess I'm looking for a Server.MapPath
equivalent so that I could use ~ to get a path relative to root but how do I insert that into my HTML?
Update: The problem is caused by the fact that my project runs in a subfolder of LocalHost root on my machine开发者_如何学Go. In Production the project is in the root itself and this problem doesn't occur.
You're looking for ResolveClientUrl
or ResolveUrl
.
精彩评论