Relative url returned in hyperlink field

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
 
J

Jonathan Wood

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}"
 
J

John

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
 
M

Munna

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top