Click here to Skip to main content
15,939,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can you please help me to show an image inside a repeater which is bound to an IEnumerableobject using LINQ.

I want to view the image properly in the web page.
Updated 24-Nov-09 22:35pm

1 solution

View image in repeater does not relates anything in LINQ.

Using Linq you create IEnumerable List, so just bind it to the Repeater control using

Repeater.DataSource = IEnumerableObject;

Now to view image you need to store the image into a valid location (might be a temporary folder) / you can directly write in Response Stream.

Do this in ItemDataBound eventhandler.

protected void rptImages_ItemDataBound(object sender, RepeaterItemEventArgs e)
  if (e.Item.ItemType == ListItemType.AlternatingItem || 
                e.Item.ItemType == ListItemType.Item)
string imagename = yourimagename;
HtmlImage imgImage = e.Item.FindControl("img") as HtmlImage;
string imagepath = Path.Combine(Path.Combine(Request.PhysicalApplicationPath, 
"tempImages"), imagename);
if (!File.Exists(imagepath))
      File.WriteAllBytes(imagepath, image.Image);
 imgImage.Src = "~/tempImages/" + imagename;
imgImage.Attributes["title"] = imagename; 

Remember to modify yourimagename with the filename you want for the particular image.

I have shown this using temporary folder, you can easily modify this using a separate handler and write the entire filebytes in response stream.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900