更改基URL ASP HyperLinkColumn [英] Changing base URL for ASP HyperLinkColumn
问题描述
我有一个简单的code列出与的DataGrid
文件。它的服务器端code:
I have a simple code to list files with DataGrid
. It's the server side code:
Dim dirInfo As New DirectoryInfo(Server.MapPath("~\images\"))
articleList.DataSource = dirInfo.GetFiles("*.*")
articleList.DataBind()
.aspx页面中标记:
.ASPX page tag:
<asp:DataGrid runat="server" id="articleList" Font-Name="Verdana"
AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee"
HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White"
HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name"
HeaderText="File Name" Target="_blank"/>
<asp:BoundColumn DataField="LastWriteTime" HeaderText="Last Write Time"
ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" />
<asp:BoundColumn DataField="Length" HeaderText="File Size"
ItemStyle-HorizontalAlign="Right"
DataFormatString="{0:#,### bytes}" />
</Columns>
</asp:DataGrid>
它列出了 HTTP文件://本地主机/图像
,但的.aspx 文件的位置是的http://本地主机/ CP / list.aspx
则超链接的位置是这样的: HTTP://localhost/cp/myfile.jpg
,因为文件的位置为 HTTP://localhost/images/myfile.jpg
我怎样才能解决这个问题?
It lists files in http://localhost/images
but .aspx file location is http://localhost/cp/list.aspx
then hyperlinks location is something like this: http://localhost/cp/myfile.jpg
since the file location is http://localhost/images/myfile.jpg
.
How can I fix it?
推荐答案
您可以使用<一个href=\"http://msdn.microsoft.com/en-IN/library/system.web.ui.webcontrols.hyperlinkcolumn.datanavigateurlformatstring.aspx\"相对=nofollow> DataNavigateUrlFormatString
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name" DataNavigateUrlFormatString="http://localhost/images/{0}" HeaderText="File Name" Target="_blank"/>
下面 {0}
将是你的形象的名字即名称
列的值。
Here {0}
will be your image name i.e. Name
column Value.
这篇关于更改基URL ASP HyperLinkColumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!