Relative url returned in hyperlink field

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

In a bound grid view I have the following hyperlink field;

<asp:HyperLinkField
DataNavigateUrlFields="FldDirections"
DataNavigateUrlFormatString="{0}"
HeaderText="Directions"
Target="_blank"
Text="Directions">
<HeaderStyle ForeColor="White" />
</asp:HyperLinkField>

FldDirections is coming from the underlying source and provides a url such
as www.mydomain.com. Problem is clicking on this hyperlink brings the url
relative to were the site is running ie something like
http://localhost/Folder1/Folder2/www.mydomain.com. How can I just get the
value retuned by FldDirections i.e. www.mydomain.com?

Thanks

Regards
 
Is it because you don't have a protocol prefix? Seems like the browser
doesn't figure out it's a domain.

What if you try something like this:

DataNavigateUrlFormatString="http://{0}"
 
Thanks. Anyway to make it conditional i.e. if FldDirections returns the url
with http:// then it is shown as it is and if without http:// then http://
is appended?

Thanks again

Regards
 
Hi
I forget to mention another easy way...
add a public method in your aspx page ...
and pass the item to format the string...

for example in code behind file add a method like this

public string GetFormatedURL(object arg)
{
string args = arg.ToString();

if (args.Contains("http://"))
return args;
else
return "http://" + args;
}

and in aspx page use it like

<asp:TemplateField HeaderText="Url" SortExpression="value">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# GetFormatedURL( Eval("value") ) %>' Target="_blank"
Text='<%# Eval("value") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
 
Back
Top