---
title: "Default image not shown in ASP ImageField"  
description: "Default image not shown in ASP ImageField"  
author: "Allen Scott"  
published: 2015-01-29  
updated: 2015-01-29  
canonical: https://www.mindstick.com/forum/12917/default-image-not-shown-in-asp-imagefield  
category: "asp.net"  
tags: ["c#", "gridview"]  
reading_time: 1 minute  

---

# Default image not shown in ASP ImageField

In my [asp.net](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) [gridview](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) there's an ASP ImageField,When [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) is not shown or broken I need to show the [Default](https://www.mindstick.com/interview/12771/what-is-the-importance-of-default-resources) Image, here I use NullImageUrl for this but this won't work.

My [Code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

<asp:ImageField DataImageUrlField="FilePath" ControlStyle-Height="50" ControlStyle-Width="50" HeaderText="Image [Preview](https://www.mindstick.com/forum/429/i-want-to-get-full-path-of-lt-asp-fileupload-gt-and-then-client-can-click-the-preview-button-to-see-what-file-he-here-has-uploaded)" NullImageUrl="~/[images](https://www.mindstick.com/interview/1067/what-is-the-php-predefined-variable-that-tells-the-what-type-of-images-that-php-support)/Defaultimg.png" />

## Replies

### Reply by Anonymous User

```
<asp:Image class="fbimgsize" ImageUrl='<%#FormatURL(Convert.ToString(DataBinder.Eval(Container.DataItem,
"picture"))) %>'  runat="server" ID="imgUser" />public string FormatURL(string img)    {        try        {            if (Path.GetExtension(img).Equals(".jpg",StringComparison.InvariantCultureIgnoreCase))            {                return img;            }            else            {                return "images/noimage.jpg";            }        }        catch (Exception)        {           return "images/noimage.jpg";        }     }
```


---

Original Source: https://www.mindstick.com/forum/12917/default-image-not-shown-in-asp-imagefield

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
