I get image by image-handler in first page and how to pass into second page
The .aspx page is like
<asp:Image ID="Image1" runat="server" Height="250px" Width="290px"
ImageUrl='<%# "ImageHandler.ashx?ImID="+ Eval("idnews") %>' />
Just pass the name of the image on the second page and set the same on the second page.
Try this code and implement according to your code
<asp:HyperLink
ID="lnkImage" runat="server"
ImageUrl='<%# Eval("productid","~/Handler.ashx?productid={0}") %>'
NavigateUrl='<%# Eval("productid","ProductLarge.aspx?productid={0}")' />
and markup in ProductLarge.aspx should be,
<img src='Handler.ashx?productid=<%=Request["productid"] %>' alt='Large Image' />
You are fetching image from database, so its not very big deal. You can just pass the Image id via Query string or other method and can display image as u display it on previous page.
Related
This is my code in aspx file
cnn.Open();
SqlDataAdapter da1 = new SqlDataAdapter("select * from carousel", cnn);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
Rp1.DataSource = dt1;
Rp1.DataBind();
cnn.Close();
and this is repeater
<asp:Repeater id="Rp1" runat="server">
<ItemTemplate>
<div class="item">
<asp:Image ID="Image1" ImageUrl='<%# Eval("image") %>' runat="server" />
</div>
</ItemTemplate>
<footertemplate></footertemplate>
</asp:Repeater>
I tried everything but I am getting in result every time I really want some help on this, I am new to ASP.Net
This is because the value coming from the database is a byte array representing the actual data of the image. Whereas the src of an img tag expects a URL to an image. There are essentially two ways to go about this...
Create a separate page (or ASHX handler preferably) which returns only the data for the image (no HTML or anything like that) and link to that page.
Base-64 encode the byte array and include that as a data URI in the src attribute.
There are lots of tutorials for the first option online. This one was found by a quick Google search, there are others as well. Essentially what the handler would do is accept an identifier on the query string, use that identifier to get the image from the database, then write the appropriate headers and content to the response. The URL for the src attribute would then be that handler. Something like:
ImageUrl='<# "~/handler.ashx?id=" + Eval("id") #>'
(Or whatever your data-bound data uses as an identifier for the image.)
suppose your image column name in database "ImageName" then
Solution 1:if your image in Root Folder
<img src='<%#Eval("ImageName")%>' alt="" />
OR
<asp:Image ID="Image1" ImageUrl='<%#Eval("ImageName")%>' runat="server" />
Solution 2:if your image in images Folder
<img src='<%# "images/" + Eval("ImageName") %>' alt=""/>
OR
<asp:Image ID="Image1" ImageUrl='<%# "images/" + Eval("ImageName") %>' runat="server" />
Your Final Solution:
<asp:Repeater id="Rp1" runat="server">
<ItemTemplate>
<div class="item">
<img src='<%#Eval("ImageName")%>' alt="" />
OR
<asp:Image ID="Image1" ImageUrl='<%# "images/" + Eval("ImageName") %>' runat="server" />
</div>
</ItemTemplate>
<footertemplate></footertemplate>
</asp:Repeater>
You need to convert in URI for IMG HTML tag:
<img src="<%# System.Text.Encoding.ASCII.GetString(Eval("bynarydatacolumn")) %>" />
or equivalent.
I'm new to ASP.NET and C# and also new to this forum but here is my problem.
I'm trying to create a image gallery with ASP.NET Webforms(requirement) and C#. I'm using a Listview to show the thumbnails and when you click on the small picture the big version should show above in a img tag for example. But I cant find any "OnClick" code for a hyperlink. Do I have to do that with JavaScript?
Thanks for all help.
here is some of the code:
<ItemTemplate>
<asp:HyperLink ID="ImageHyperLink" runat="server" ImageUrl='<%# Eval("Name","~/files/thumbs/{0}") %>' NavigateUrl='<%# Eval("Name","~/files/{0}") %>'></asp:HyperLink>
</ItemTemplate>
Try taking a look at LinkButton
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton(v=vs.110).aspx
<asp:LinkButton runat="server" id="LinkButton1" OnClick="OnClickAction"></asp:LinkButton>
This will allow you to do a server-side method in much the same way an <asp:Button> will do. However will look just like a hyperlink.
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="http://stackoverflow.com/">HyperLink</asp:HyperLink>
You will not get on click event for HyperLink, But for navigating on to the another page.
You will get one property which is NavigateUrl
By using this property you can redirect to any page by giving url.
When I use photos without any folder, <asp:Image ID="Image1" ImageUrl='<%# Eval("PresidentPhotoPath") %>' runat="server" /> , it works.
However, when I use the photos under Images folder, the pictures are not shown and I get a blank screen only. Here is the code I'm using:
<div class="wrapper">
<asp:Repeater runat="server" ID="Repeater1">
<ItemTemplate>
<asp:Image ID="Image1"
ImageUrl='"/Images" + <%# Eval("PresidentPhotoPath") %>'
runat="server" />
</ItemTemplate>
</asp:Repeater>
</div>
Change asp:Image to code bellow:
<asp:Image ID="Image1"
ImageUrl='<%# string.Format("~/Images/{0}", Eval("PresidentPhotoPath")) %>'
runat="server" />
I would recommend using a code-behind method to build the string for you, like this:
protected string BuildPath(string photoPath)
{
return "Images/ + photoPath;
}
Note: Consider naming this something more useful than BuildPath as that is fairly generic, just picked that name because nothing better came to mind immediately.
Now in your markup you can just call the method, like this:
ImageUrl='<%# BuildPath(Eval("PresidentPhotoPath")) %>'
I recommend this approach for the following reasons:
The markup does not contain any complex logic whatsoever, just a method call with the Eval() value
It is easier to debug the logic versus embedded code blocks
You can leverage the power of Visual Studio compiler to catch syntax errors at compile-time versus run-time errors when the logic is embedded into the binding syntax of the markup
I have 2 images in my page. What i want to do is, when i move the mouse over 2nd image, the first image will change to other image, but something is not working.
Code:
<asp:Image ID="imgProduct" runat="server" ImageUrl="~/Images/1.png" />
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/2.png" onmouseover="imgProduct.src='Images/2.png';"/>
If i change the ID in onmouseover="imgProduct.src= to any image id in masterpage, that image is changing correctly, but its not working in the default page.
Any suggestions?
On Page_Load event add this line.
Image2.Attributes.Add("onmouseover",imgProduct.ClientID+".src='Images/2.png'");
Try this instead :
<asp:Image ID="Image1" runat="server" ImageUrl="~/Images/2.png"
onmouseover="javascript:document.getElementById('imgProduct').src=this.src;" />
Good Luck !!
<asp:ImageButton ID="Imagebtn" runat="server" ImageUrl=retriveurl('<%# Eval("id") %>') CommandName="viewalbum" CommandArgument='<%# Eval("id") %>' />
<asp:Label ID="product_nameLabel" runat="server"
Text='<%# Eval("product_name") %>' />
i want to set image url from another database table using Eval("id").query can return several row.but i want to set the last url from datareader.
If you want to bind the last url from dataTable you can customize your datasource by calling a separate method which would return you the required url and then the updated datasouce can be binded.