Jumping to external url from gridview template field
I need to jump from existing location to some other location. Like if my application is running on localhost, and i want to jump to Youtube. Scenario:
I have a grid in which template field is asp开发者_开发百科:hyperlink. I need to add a image and on on that image click, i will get moved to youtube.
<a id="Download" href='<%#ResolveUrl(Eval("Path").ToString()) %>'
title="Download>>" style="color: #FFFFFF; font-size: 9pt">
<img src="~/images/dl.gif" style="border:0px; height:22px; width:22px"
alt="Download" runat="server"/></a>
<asp:HyperLink runat="server" ID="HyperLink1"
NavigateUrl='<%# ResolveUrl(Eval("YouTubeUrl").ToString()) %>'>
<img src="~/images/yt.gif" style="border:0px; height:22px; width:22px"
alt="Play on You tube" runat="server" /></asp:HyperLink>
I want to navigate some other location outside the current location from the current location.
Use this
<a id="Download" href='<%#ResolveUrl(Eval("Path").ToString()) %>'
title="Download>>" style="color: #FFFFFF; font-size: 9pt">
<img src="~/images/dl.gif" style="border:0px; height:22px; width:22px"
alt="Download" runat="server"/></a>
<asp:HyperLink runat="server" ID="HyperLink1"
NavigateUrl='<%# Eval("YouTubeUrl").ToString().Contains("http://")?Eval("YouTubeUrl"):"http://"+Eval("YouTubeUrl").ToString() %>'>
<img src="~/images/yt.gif" style="border:0px; height:22px; width:22px"
alt="Play on You tube" runat="server" /></asp:HyperLink>
You should use something like this:
<asp:HyperLink runat="server" ID="HyperLink1"
NavigateUrl='<%# string.Format("http://{0}", Eval("YouTubeUrl").ToString()) %>'>
If this ends up with two http:// at the start then change it to this:
<asp:HyperLink runat="server" ID="HyperLink1"
NavigateUrl='<%# Eval("YouTubeUrl").ToString() %>'>
Its not clear from what you've posted if the ResolveUrl call is breaking it or if your YouTube url contains the protocol at the start.
精彩评论