Click here to Skip to main content
15,076,465 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have program in which images are stored as byte in database and are retrieved and displayed in gridview and then to the label. Some code numbers didn't have images in database. I need to set default images when ever the image is null. I need to show it only in the label. Instead of image button I have used label to display the images.

Here is the code for displaying image to the gridvie from database.
XML
<img src='data:image/jpg;base64,<%# Eval("img") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("img")) : string.Empty %>' alt="image" height="250px" width="275px"/>


And here is the code for displaying images in the label
C#
Label62.Text = ((ITextControl)GridView1.Rows[0].Cells[55].Controls[0]).Text;


so how can I set a default image to the label, whenever the image is null.
Posted
Updated 24-Jan-15 0:23am
v3

1 solution

Hi,
I think you can you use onerror property, if your image not found the set default image.
like that..

<br />
<img src="data:image/jpg;base64,<%# Eval("img") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("img")) : string.Empty %>" />



Maybe it is help full for you.

Thanks
Mohit Saxena
   
v4
Comments
Member 11357862 26-Jan-15 1:28am
   
Sir could u pls explain

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900