Reputation: 1070
I have an ASP.NET gridview control with a custom column that is an anchor tag and I'm having some issues with setting the URL.
Based on what I've constructed below, I would expect the that the HREF would come through as "myhost.local/Orders/FileName.PDF", but what I'm seeing it come through as"myhost.local/current directory/current page/myhost.local/Orders/FileName.pdf". Any assistance would be greatly appreciated!
The Gridview
<asp:GridView ClientID="GV" AllowPaging="true" OnPageIndexChanging="gv_Search_PageIndexChanging" PageSize="10" ID="gv_Search" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField HeaderText="Disciplinary Orders" SortExpression="defendant_name">
<ItemTemplate>
<a href="<%# HttpContext.Current.Request.Url.Host %>/Orders<%# Eval("FileName") %> " target="_blank">
<%# Eval("FullName") %> - <%# Eval("CaseNumber") %> - Get Disciplinary Status </a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Upvotes: 1
Views: 454
Reputation: 1070
I was able to get the correct URL by changing to an ASP HyperLink and using String.Format()
<ItemTemplate>
<asp:HyperLink
runat="server"
id="link"
NavigateUrl='<%#String.Format("{0}", "/Orders/" + Eval("FileName")) %>'
Target="_blank">
<%# Eval("FullName") + " - " + Eval("CaseNumber") %> - Get Disciplinary Status
</asp:HyperLink>
</ItemTemplate>
Upvotes: 1