Aakash Singh Aakash Singh - 1 year ago 65
C# Question

I want to display an image on a grid view column if it is null and other image if its not null

<asp:BoundField HeaderText="Assigned Tag" DataField="NBFCTagID"/>

If value of NBFCTagID is null then I want to display

I already tried
but it wasn't very helpful.

Answer Source

Add template field like this.

       <asp:Image ID="imgStatus" runat="server" CssClass="label" ImageURL='<%# GetImage((object)Eval("NBFCTagID")) %>' />

 public static string GetImage(object value)
        if (value != null)
            return "../Images/green_mark.jpg";
            return "../Images/red_mark.jpg";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download