I have an asp.net web application in which the images from gridview is displayed on a label. I have used this code for displaying image in gridview
<ItemTemplate>
<img src='data:image/jpg;base64,<%# Eval("img") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("img")) : string.Empty %>' alt="image" height="250px" width="275px"/>
ItemTemplate>
This code is used to display the image from gridview to the label.
Label2.Text = ((ITextControl)GridView1.Rows[0].Cells[55].Controls[0]).Text;
in my gridview some image field value are null. some products not have images in the database. So how can set a default image for the label when the image is null.

Saineshwar BageriRank #115 · 19.6K reputationPosted Jan 26, 2015, 6:18 PM EST
Check the value is blank or not if blank or null then apply default images
else what ever image coming from database.
Santhakumar MunuswamyRank #128 · 17.3K reputationPosted Jan 26, 2015, 6:36 PM EST
First, could you check image field coulmn data is null or empty then you can set the default image in codebehind rowdatabound event
Ex.
vishnu suresh53 reputationPosted Jan 26, 2015, 7:33 PM EST
Saineshwar BageriRank #115 · 19.6K reputationPosted Jan 26, 2015, 7:43 PM EST
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if(label.text == string.empty)
{
img.src =" default image ";
}
else
{
img.src = database value;
}
}
}
Mark as answer if i had resolved issue
vishnu suresh53 reputationPosted Jan 28, 2015, 1:42 AM EST
Pls see my code, if there is no image it will display no image. I have set alt=no image. Instead of this how can I put an alternate image on this.
<img src='data:img/jpg;base64,<%# Eval("img") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("img")) : string.Empty %>' alt= "no image" height="75px" width="100px"/>
Saineshwar BageriRank #115 · 19.6K reputationPosted Jan 28, 2015, 1:43 AM EST
vishnu suresh53 reputationPosted Jan 28, 2015, 3:21 AM EST
vishnu suresh53 reputationPosted Jan 28, 2015, 3:22 AM EST
Saineshwar BageriRank #115 · 19.6K reputationPosted Jan 28, 2015, 3:33 AM EST
http://www.aspdotnet-suresh.com/2011/01/how-to-insert-images-into-database-and.html