Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get my image to work with my asp:hyperlink?

Status
Not open for further replies.

InsideEdge

Instructor
Apr 5, 2005
35
US
Hi everyone,

I am retrieving images from a file and I’m using the database field that contains the image file’s name. The images are displayed in a DataGrid which has the image name bounded to the underlying database. The database finally gets the image from a folder called "images".

When I use a common HTML tag, the image works but an asp: hyperlink only shows the empty place holder or he image but not the image.



Here’s the code that works:

<IMG src='images/<%# DataBinder.Eval(Container.DataItem, "ImagePath") %>'

Here’s the code that doesn’t work:

<asp:HyperLink id=HyperLink1 runat="server" CssClass="DepartmentUnselected" ImageUrl ='<%# DataBinder.Eval(Container.DataItem, "ImagePath") %>' NavigateUrl="../login.aspx " ></asp:HyperLink>

I can click the place holder for the image and the link works perfectly. The only thing is there is no picture, just the placeholder. How can I make the second piece of code read my image from a bounded field in the DataGrid?



Please help.
 
Have a look at the View Source for both methods and see what the differences are. Paste them both here if you can't spot anything.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Here's a portion of the code. I hope this helps.

<TABLE cellPadding="0" align="left">
<TR>
<TD align="center" width="110"><IMG src='images/48.jpg' vspace=10 border=0></A>
</TD>
<TD vAlign="top" width="200" height="200"><FONT class="ProductName">Pelican Bay</FONT><BR>
<BR>
<FONT class="ProductDescription">
Relax at the mouth of a beautiful beach town.
<BR>
<BR>
Price: </FONT><FONT class="ProductPrice">
$45.33
<BR>
<BR>
<input type="submit" name="_ctl1:productsList1:list:_ctl2:Button1" value="Add to Cart" id="_ctl1_ProductsList1_list__ctl2_Button1" /></FONT>
<a id="_ctl1_ProductsList1_list__ctl2_HyperLink1" class="DepartmentUnselected" href="login.aspx"><img src="UserControls/48.jpg" alt="" border="0" /></a>
</TD>
</TR>
</TABLE>
 
The code the html is producing for your image is:
<img src="UserControls/48.jpg" alt="" border="0" /> with the path being UserControls/48.jpg

In your example that you said "worked" you have "images/" before your path. That isn't in your hyperlink path.

Is this your problem?
 
No, this isn't the problem. I've tried adding "images/" before the path.
 
You could do something like this..

Code:
<a href="../login.aspx"><IMG src='images/<%# DataBinder.Eval(Container.DataItem, "ImagePath") %>' /></a>
 
Hi jshurst,

That piece of code totally worked!!!! I've searching forums and asking for help with this one for weeks and finally I found the person that knows how this stuff works. Thank you so much for your help!!

InsideEdge
 
No, this isn't the problem. I've tried adding "images/" before the path.
You say you've tried adding the "images" folder to the path and it doesn't work yet the example that jshurst gave does exactly that and it does work (it's irrelevant that he gave you an example with a HTML anchor tag as the HyperLink control would work in exactly the same way).



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi ca8msm, I guess you were right about me needing to add the correct path to the image folder, "images/". I would like to send parameters through NavigateUrl to other pages so I went back to using the asp:hyperLink and put the "img src ="
in the asp:HyperLink tag. It worked. Thanks for your input. Here's the code.

<asp:HyperLink id="Hyperlink2" runat="server" CssClass="DepartmentUnselected" NavigateUrl="../EnlargedImage.aspx " ><img src='images/<%# DataBinder.Eval(Container.DataItem,"ImagePath") %>'/>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top