I have the following piece of code
ImageUrl='<%# Bind("ImageUrl") %>'
I've got a GridView I want to show images on a ItemTemplate
I have a Database where I'm saving on the name of the images e.g --> img1.jpg
I want to append the full path of the image at before its name so It can be viewed on the ItemTemplate on the GridView.
I tried to use concat, or the + operator but it doesn't seem to work
can any1 tell me what 2 do ???
Use inline Eval like this ImageUrl='<%# "path/to/image" + Bind("ImageUrl") %>'
No need to use Bind. Its used for two-way, read/write databinding.
Hi try this it ll works
' height="120" width="180" alt="" />
' OnClick="BtnImg_Click" height="120" width="180"/>
Related
I m fetching the image name path from vb.net and want to pass it to image URL in asp.net.. How to do... I m doing this but display nothing
IN Vb.net
dim myLogo as string = ResolveUrl("C:\Test\Logo\" & img_name)
Me.DataBind()
IN ASP.net
<asp:Image ID="test" ImageUrl='<% myLogo %>' runat="server" Height="100px" Width="100px" />
ASP.NET includes the Web application root operator (~), which you can use when specifying a path in server controls. ASP.NET resolves the ~ operator to the root of the current application. You can use the ~ operator in conjunction with folders to specify a path that is based on the current root.
The following example shows the ~ operator used to specify a root-relative path for an image when using the Image server control In this example, the image file is read from the Images folder that is located directly under the root of the Web application, regardless of where in the Web site the page is located.
<asp:image runat="server" id="Image1"
ImageUrl="~/Images/SampleImage.jpg" />
You can use the ~ operator in any path-related property in server controls. The ~ operator is recognized only for server controls and in server code. You cannot use the ~ operator for client elements.
For more details refer:
ASP.NET Web Project Paths
Eg.
dim myLogo as string = "~\Logo\" & img_name
Surely the url to the file will be:
"file://c:\Test\Logo\" & img_name
Have you tried that?
Try this
<asp:Image ID="test" ImageUrl='<%= myLogo %>' runat="server" Height="100px" Width="100px" />
You need to declare myLogo variable as protected in general section of code and in aspx page you can use folling code to bind imageurl.
<asp:image runat="server" Height="100px" Width="100px" imageurl='<%#myLogo%>' />
Please let me know if this does not work.
I am using a listview to display a list of all the users of my site. A user can upload multiple images, so when i generated my model with entity framework, 2 entities were created: Users and Images. User had a navigation property to a collection of images and Images had a navigation property to a single user.
I am now trying to display in my listview 1 of the images uploaded by the user (if he has uploaded any).It doesn't matter which one is being displayed.
I created an EntityDataSource, and i've added "Images" into it's include property. Then, i branched my listview to the datasource. usually, to display the content of the navigation property, i use something like
<asp:Label ID="fn" runat="server" Text='<%# Eval("Users.Firstname") %>' />
However, since it's column of a collection that i'm trying to display,can i use something like this? IF so, what would be a propper way to manage the case where the user didn't upload any image?
<asp:image ID="img" runat="server" ImageUrl='<%# Eval("Images[0].path") %>' AlternateText="" />
Eval is using reflection and it has its limitations on more complicated terms. You should not be afraid of direct casting:
<asp:image ID="img" runat="server"
ImageUrl='<%# ((YourObjectType)Container.DataItem).Images[0].path") %>'
AlternateText="" />
Note that in order to cast to YourObjectType you will probably have to add an <#Import > directive to the page (or alternatively use a full type name, including the namespace).
Is there a way to embed an expression builder within a larger string?
I'm trying to create a hyperlink where the URL includes an embedded expression. I tried writing
<asp:hyperlink id="add" runat="server" text="Add" NavigateUrl="~/admin/customer.aspx?code=<%$ AppSettings:salecode %>&action=add" />
But this didn't work -- the "<%$" and all just got included as text, no substitution was done.
Of course I could build the URL in code, it's no big deal, but I just wonder if it's possible to do this in the ASPX file somehow.
PS Just as a test, I tried putting
<asp:label id="test" runat="server" text="<%$ AppSettings:salecode %>" />
and that worked fine, so it's not that I'm mis-spelling the setting name or something dumb like that.
Try using single quotes around the NavigateUrl property:
NavigateUrl='~/admin/customer.aspx?code=<%$ AppSettings:salecode %>&action=add'
I'm using a jquery slideshow and I want to fill in the pictures from a database. I'm trying to use an ASP repeater to create the images in a div with this code.
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="dsSelectedCategory" Visible="True">
<ItemTemplate>
<a><asp:Image ID="Image2" runat="server" ImageURL="~/img1/photos/<%#Eval("PictureFilePath") %>" class="slide" /></a>
</ItemTemplate>
</asp:Repeater>
I'm getting the error that the server tag is not well formed and I'm guessing it is this bit
ImageURL="~/img1/photos/<%#Eval("PictureFilePath") %>"
PictureFilePath is a field in the database that holds the filename and extension of the file. So I have to write out the path to the file then add on the name.
Try
ImageURL='<%# "~/img1/photos/" + Eval("PictureFilePath") %>'
I have tried your code and found the answer. Finally, it solved my problem as well. Just mark as answer if worked for you.
This is your old code
ImageURL="~/img1/photos/<%#Eval("PictureFilePath") %>"
change it to
ImageURL='~/img1/photos/<%#Eval("PictureFilePath") %>'
replace the double quotes "" with single quotes ''
HI
Im trying to show an image in a gridview, its held on the filesystem and the filename is returned in the datasource query.
If the files are held in C:\TEMP, how would I properly structure the code below?
thanks
<asp:Image ID="Image" runat="server" ImageUrl='<%#"C:\TEMP\" + Eval("ImagePath") %>'
I believe it is along these lines
<asp:Image ID="Image" runat="server" ImageUrl="C:\TEMP\<%= Eval("ImagePath") %>"/>
In this scenario, your ImageUrl value needs to be relative to the root of your web application so if your webapp is in:
c:\iis\MyWebApp
and images are in:
c:\iis\MyWebApp\img the ImageUrl should evaluate to something like ~/img/Img1.jpg
You could store the full path e.g. `~/img/Image1.jpg' in the db or just the filename, in which case you need to add the path to the ImageUrl value either in code-behind or in the markup.
See this article for more information.
Hth.