开发者

How can I resolve relative paths in an ASP ListView template?

开发者 https://www.devze.com 2023-03-05 18:19 出处:网络
I use a ListView to display (funnily enough) a list of data, including a hyperlink. Here is my item template (ascx file):

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消