Steve
Steve

Reputation: 41

Cannot Display Image from List

I'm trying to display ListItems in a GridView.

I am able to access the list items but my image is getting displayed as url .

I am using:

dr["Category"] = SPEncode.HtmlEncode(Convert.ToString(oListItem["Category"]));

The above line of code displays the list items, but when I try to display the images, it renders as http://server/images/xyz.jpg in the gridview.

Please help me in accessing the list images.

Update:

With regard to Alan's answer:

I have tried this:

foreach (SPListItem oListItem in collListItems) {
    dr["Category"] = 
         SPEncode.HtmlEncode(Convert.ToString(oListItem["Category"]));
}

But when i try to display the images:

dr["ProductImage"] = 
       SPEncode.HtmlEncode(Convert.ToString(oListItem["ProductImage"]));

It still renders as: http://server/images/xyz.jpg in the gridview.

Upvotes: 1

Views: 635

Answers (3)

Ciprian Grosu
Ciprian Grosu

Reputation: 2831

You can try the solution provided here:

http://cipriangrosu.blogspot.com/2009/05/display-item-type-icon-in-spgridview.html

Upvotes: 1

Magnus Johansson
Magnus Johansson

Reputation: 28325

Are you using the ASP.NET GridView? In that case you can set the filed property to your image column to Image Field. Then you can assign the value of your converted oListItem["ProductImage"] field to the PictureUrl field.

Here's an example to get you started:

http://msdn.microsoft.com/en-us/library/aa479350.aspx

Upvotes: 1

Alan McBee
Alan McBee

Reputation: 4320

This question could use a few more details. It would help to know what oListItem[key] and dr[key] were arrays of. Whatever it is, it looks like oListItem[].ToString() method just returns a URL.

Couldn't you just new up an Image control, set the ImageSrc propery, and then add it into the GridView? You need to instantiate a new Image with each row (don't reuse an Image).

Upvotes: 1

Related Questions