Home > DeveloperSection > Forums > Default image not shown in ASP ImageField
Allen Scott

Total Post:37

Points:261
Posted on    January-29-2015 10:20 PM

 ASP.Net C#  Gridview 
Ratings:


 1 Reply(s)
 654  View(s)
Rate this:

In my asp.net gridview there's an ASP ImageField,When image is not shown or broken I need to show the Default Image, here I use NullImageUrl for this but this won't work.

My Code:

<asp:ImageField DataImageUrlField="FilePath" ControlStyle-Height="50" ControlStyle-Width="50" HeaderText="Image Preview" NullImageUrl="~/images/Defaultimg.png" />



Chris S
Chris S

Total Post:48

Points:336
Posted on    January-29-2015 10:41 PM

<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";

        }

 

    }


Don't want to miss updates? Please click the below button!

Follow MindStick