[Solved] Binary Images are not displaying in ASP.Net GridView

Last Reply 17 days ago By akhter

Posted 18 days ago

I am trying to display image in gridview but images are not getting display in gridview.

https://i.ibb.co/tZJGhjQ/imageview.jpg

 

Posted 17 days ago Modified on 17 days ago

i was just making a mistak that in FindControl, i was using column "Data" instead of ID ("img") .

protected void gvDepartments_RowDataBound(object sender, GridViewRowEventArgs e)
{ 
    try
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView dr = (DataRowView)e.Row.DataItem;
            string imageUrl = "data:image/jpg;base64," + Convert.ToBase64String((byte[])dr["Data"]);
            (e.Row.FindControl("img") as System.Web.UI.WebControls.Image).ImageUrl = imageUrl;
        }
    }
    catch (Exception ex)
    { }
}