Listview

Asked

Viewed 109 times

0

Difficulty: Display an image in the List View control template item. The datasource property of the controller is populated with a collection. In the collection, the image returns from Sqlserver as an array of bytes. Hence I need to convert it to image in the control template item.

         <ItemTemplate>
                <h2><%#Eval("titulo")%></h2>                                                                                                                      
                <p><h5><%#Eval("texto")%></h5></p>                                             
                <h6><%#Eval("data", "{0:d}")%></h6>   
                imagem convertida aqui
        </ItemTemplate>     
  • Is it ASP.NET? Or what language?

  • yes, Asp.net thank you

  • I edited with a new tag to highlight the language, so a developer who has the same knowledge in ASP.NET has greater visibility on the question. Enjoy a tour of Stackoverflow to make the most of the features offered: http://answall.com/tour. Welcome.

  • yes quiet. thank you.

1 answer

0

To return an Image see if the code below helps you:

public Image byteArrayToImage(byte[] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Image returnImage = Image.FromStream(ms); return returnImage; }

If you prefer a Bitmapimage:

public BitmapImage ImageFromBuffer(Byte[] bytes) { MemoryStream stream = new MemoryStream(bytes); BitmapImage image = new BitmapImage(); image.BeginInit(); image.StreamSource = stream; image.EndInit(); return image; }

  • ok, thank you. I would like to convert directly into control.

  • You can do this conversion the moment you are creating your object, then in its image attribute you do the conversion. If I understand your question rsrsrsr take a look at this question. http://stackoverflow.com/a/2629921/3737742

  • Check this out: http://www.codeproject.com/Tips/445876/Auto-bind-byte-to-asp-Image

  • the object is of type byte[]. If I convert I can not add in the collection. So I need to convert in control.

  • namespace Objectcransference { public class Blogsite { public int textoID { get; set; } public string title { get; set; } public string text { get; set; } public Datetime Data { get; set; } public byte[] image { get; set; } } }

  • studied many examples. I would have to change the project to suit. I look for the conversion solution directly in control.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.