Question on Asp:Repeater
Hi,
I have an product catalog page for online shopping.
This is the sample of the DataSet
ID Name ThumbnailImage BigImage
1 Product A productA.jpg productA_big.jpg
2 Product B productB.jpg <NULL>
3 Product C <NULL> <NULL>
I'd like to display the data in a way that the thumbnail and a link to the big image would only be shown when necessary, like this:
<a href="productA_big.jpg" target="_blank">
<img src="productA.jpg">
</a><br>
Product A
<hr>
<img src="productB.jpg"><br>
Product B
<hr>
Product C
<hr>
I'm using a repeater but it's trying to show the thumbnail even when there's no file, and provide the link even when I don't want it to...
Is there anyway I can control the Repeater?
WB.
[952 byte] By [
namewb] at [2008-2-14]
Hi,
Create a function with two input arguments ThumbnailImage & BigImage and which return a string depending on these two inputs as you wish. then use the function in repeater data binding like below
<asp:Repeater ....>
<ItemTemplate>
<%#GetHtml(DataBinder.Eval(Container.DataItem,"ThumbnailImage"),DataBinder.Eval(Container.DataItem,"BigImage"))%>
</ItemTemplate>
</asp:Repeater>
Get Html function in code behind or in server side inline page script
public string GetHtml(object ThumbnailImage,object BigImage)
{
string result;
// Write your logic here ThumbnailImage.ToString() will return string value
//for example to display only link when thumbnailimage is available
if(ThumbnailImage!=null)
{
result = result + "<a href=\"" + ThumbnailImage.ToString() + "\" target=\"_blank\">";
}
}
Robincurry,
Great answer above! Here is my situation: I am trying to disply images in a repeater like above; however, my images are retrieved from an SQL database. The image binary data and the image content type are both retrieved from the SQL database. I want a thumbnail version of the image displayed in the repeater, but this thumbnail should be linked to a bigger version of the thumbnail.
Here is a sample of my data:
image_data cont_type image_desc
<bin> image/pjpeg description 1
<bin> image/pjpeg description 2
<bin> image/pjpeg description 3
<bin> image/pjpeg description 4
<bin> image/pjpeg description 5
I am confused on how to use the <asp:Image> tags in combination with DataBinder.Eval(Container.DataItem, "image_data") to display my images. I can display an image using:
Response.ContentType = reader["cont_type"].ToString();
Response.BinaryWrite( (byte[]) reader["img_data"] );
Thank you for your anticipated help and assistance,
Shola.