Jumping to external url from gridview template field - c#

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.

Related

Gallery is not showing after uploading into live site using ASP.NET C#

Below I am calling my gallery using Datalist in localhost gallery is showing and live site not showing.
<asp:DataList ID="dlImages" runat="server">
<ItemTemplate>
<ul>
<li><a href="#cube">
<asp:Image ID="Image2" runat="server" class="cubeHide" ImageUrl='<%# Bind("ImageName", "/GalleryImages/{0}") %>' />
</a>
<div class="label_text">
</div>
</li>
</ul>
</ItemTemplate>
</asp:DataList>
1.Change ImageUrl from this:
ImageUrl='<%# Bind("ImageName", "/GalleryImages/{0}") %>'
To this:
ImageUrl='<%# Bind("ImageName", "~/GalleryImages/{0}") %>'
2.Make sure you have a folder called GalleryImages in the root of your website with the relevant image files.
I added simply ~ then resolve my issue:
ImageUrl='<%# Bind("ImageName", "~/GalleryImages/{0}") %>'

DataList in ASP.Net Video should be enlarge onclick

WebSiteVideo.aspx
<asp:DataList ID="DataList1" Visible="true" runat="server" AutoGenerateColumns="false" RepeatColumns="1" CellSpacing="15">
<ItemTemplate>
<a class="player" style="height: 100px; width: 120px; display: block" href='<%# Eval("Id", "File.ashx?Id={0}") %>'>
</a>
<u>
<%# Eval("Name") %>
</u>
</ItemTemplate>
</asp:DataList>
when i am clicking the video it should be Enlarge, According to this coding what have to do? Any solution?
You have to probably call some kind of function through client side which will zoom your video.
Check this JQuery Show Large Image Preview When Hover On Link In Asp.Net

How to give if else condition in asp.net c# inside grid template?

I have written like below lines of code
<asp:TemplateField HeaderText="Marketing Document / URL" SortExpression="DocumentActualName">
<ItemTemplate>
<%# (String.IsNullOrEmpty(Eval("DocumentActualName").ToString() ) ? %>
<asp:LinkButton ID="lnkDownload" runat="server" CommandArgument='<%# DataBinder.Eval (Container.DataItem, "ProductDocument") %>'
CommandName="Download" CausesValidation="false" Text='<%# Eval("DocumentActualName") %>'> </asp:LinkButton>
<% : %>
<a id ="lnkUrl" runat="server" href='<%# Eval("URL") %>' Text='<%# Eval("URL") %>'></a>
</ItemTemplate>
</asp:TemplateField>
It's not working. Please help
You need to bring the databinding tags (<%#) outside of the Page.ResolveUrl method, and use single quotes around the href attribute:
href='<%#Page.ResolveUrl(Eval("URL"))%>'
<a href='<%# String.IsNullOrEmpty(Eval("File").ToString()) ? Eval("URL") : Eval("File") %>'> URL </a>

How can I pass the url of a selected image which is included in a listview from one aspx page to another?

I am working on my class project where I created an image gallery using listview.
The Designing is below:
<asp:ListView ID="lvPresent" runat="server" DataSourceID="SqlDataSource1">
<LayoutTemplate>
<table>
<tr>
<td></td>
</tr>
</table>
<asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<ItemTemplate>
<td>
<asp:HyperLink ID="HyperLink1" runat="server">
<asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />
</asp:HyperLink>
</td>
</ItemTemplate>
</asp:ListView>
How can I send the url of the selected image from one .aspx page to another anothe ?
To send URL to another page you can use QueryString.
Modify your HyperLink and add NavigateUrl
NavigateUrl='<%#"yourNextPageName.aspx?imgURL="+ Eval("url")%>'
just replace you code:-
<asp:HyperLink ID="HyperLink1" runat="server">
<asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />
</asp:HyperLink>
with
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#"yourNextPageName.aspx?imgURL="+ Eval("url")%>'>
<asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />
</asp:HyperLink>
Add image URL as query string ,
NavigateUrl ='yourNextPageName.aspx?imgURL=<%# Eval("url")%>'
in HyperLink
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl ='yourNextPageName.aspx?imgURL=<%# Eval("url")%>' >
<asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />
</asp:HyperLink>
In destination page , get your image url as string _imgURL =Request.QueryString["imgURL"];

Add query values to an asp Link Button

I have this Link Button here.
<li><asp:LinkButton ID="MyPDF" OnClick="Download_Click" runat="server" Text="My PDF" NavigateUrl='<%# "./DownloadableProducts.aspx?filename=MyPDF" %>'></asp:LinkButton></li>
And it doesn't work, it says "could not find file". I know it's the query string because when I put the path to the file manually, it works like a charm.
I have also tried this:
<li><asp:LinkButton ID="MyPDF" OnClick="Download_Click" runat="server" Text="My PDF" NavigateUrl='<%# "./DownloadableProducts.aspx?filename=" + Eval("ID") %>'></asp:LinkButton></li>
and it didn't work :(
<li>
<asp:LinkButton ID="MyPDF" OnClick="Download_Click"
runat="server" Text="My PDF"
NavigateUrl="~/DownloadableProducts.aspx?filename=MyPDF">
</asp:LinkButton>
</li>
Try this
<li><asp:LinkButton ID="MyPDF" OnClick="Download_Click" runat="server" Text="My PDF" NavigateUrl="./DownloadableProducts.aspx?filename="+'<%# Eval("ID") %>'></asp:LinkButton></li>
Change it to :
<asp:HyperLink ... NavigateUrl='<%# "DownloadableProducts.aspx?filename=" + Eval("ID") %>' />
The LinkButton Control has no property "NavigateUrl". this control just can do a post back for you, if you need link directly to another location use HyperLink instead.
User the CommandArgument property in the LinkButton
<li><asp:LinkButton ID="MyPDF" runat="server" Text="My PDF" NavigateUrl='<%# GetUrl(Eval("Id")) %>'></asp:LinkButton></li>
and then add into a codebehind something like this:
protected string GetUrl(string id) { return ResolveUrl(string.Format("~/DownloadableProducts.aspx?filename={0}", id)); }
<li>
<asp:LinkButton ID="MyPDF" OnClick="Download_Click" runat="server"
Text="My PDF" NavigateUrl="DownloadableProducts.aspx?filename=<%#Eval("ID") %>" >
</asp:LinkButton>
</li>
this will work

Categories

Resources