tags:

views:

106

answers:

5

I'm trying to display the 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 me the list items

but when i try to display the images, it displays to me as :

http://server/images/xyz.jpg in the gridview.

Please help me in accessing the list images.

A: 

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).

Alan McBee
A: 

Hey alan, i have tried like 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 displays to me as :

http://server/images/xyz.jpg in the gridview.

Steve
Steve - just a heads up, stackoverflow is not really like a discussion board, you should have edited your question or posted a comment rather than add this as an Answer. Check out the FAQ (top right) for some examples.
Ryan
A: 

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

Magnus Johansson
A: 

Yes, I am using the asp.net GridView and I want to display all the fields in my List, one of which is Image Column that is geeting displayed as a url instead of Image.

diane depeuy
A: 

Hello,

You can try the solution provided here: http://cipriangrosu.blogspot.com/2009/05/display-item-type-icon-in-spgridview.html

Thx .

Ciprian Grosu