How to bind byte[] to Image in ASP.NET ListView RRS feed

  • Question

  • Hello,

    I'm trying to bind a Byte[] Array with asp.image as follow

    var. 1

    <asp:Image ID="Image2" runat="server" ImageUrl='<%# String.Format("data:image/jpeg;base64,{0}",((byte[])Eval("Picture")) )  %>'   />

    and also var. 2 with Code

            protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
                if (e.Item.ItemType == ListViewItemType.DataItem)
                    System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
                    string imageUrl = "data:image/jpg;base64," + Convert.ToBase64String((byte[])rowView["Picture"]);
                    object o = e.Item.FindControl("Image1");
                    Image i = (Image)o;
                    if (i != null)
                        (e.Item.FindControl("Image1") as Image).ImageUrl = imageUrl;

    But I can't get a Picture on ASP.NET PAge.

    Whats wrong? And how can I achive this Goal?


    P.S. Visual Studio 2019, Database Nordwind, Table Categories

    Make IT better.

    Friday, May 1, 2020 9:58 PM

All replies

  • Hello,

    This forum is for C#, not ASP.NET. Use the forum below for ASP.NET questions.


    Also I noticed you are working with image1 in C# and image2 in the asp side.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Friday, May 1, 2020 11:37 PM