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 BageriPosted Jan 28, 2015, 8:33 AM
http://www.aspdotnet-suresh.com/2011/01/how-to-insert-images-into-database-and.html
vishnu sureshPosted Jan 28, 2015, 8:22 AM
vishnu sureshPosted Jan 28, 2015, 8:21 AM
Saineshwar BageriPosted Jan 28, 2015, 6:43 AM
vishnu sureshPosted Jan 28, 2015, 6:42 AM
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 BageriPosted Jan 27, 2015, 12:43 AM
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 sureshPosted Jan 27, 2015, 12:33 AM
Santhakumar MunuswamyPosted Jan 26, 2015, 11:36 PM
First, could you check image field coulmn data is null or empty then you can set the default image in codebehind rowdatabound event
Ex.
Saineshwar BageriPosted Jan 26, 2015, 11:18 PM
Check the value is blank or not if blank or null then apply default images
else what ever image coming from database.