Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends, problem is i want to show default image when the respective row don't have record.
please tell me. Thanks in adv.

XML
<asp:TemplateField HeaderText="Dr. Photo">
                    <ItemTemplate>
                        <asp:Image ID="Image1" runat="server" Style="height: 80px; width: 100px;" ImageUrl='<%# String.Format("~/Upload/Docters/" + Eval("ImgName")) %>' />
                    </ItemTemplate>
                </asp:TemplateField>
Posted

1 solution

Try using this:
C#
<asp:image id="Image1" runat="server" style="height: 80px; width: 100px;" imageurl="<%# string.IsNullOrEmpty(Eval("ImgName")) ? "~/images/default.png" : String.Format("~/Upload/Docters/" + Eval("ImgName")) %>" />

Hope it will be helpful !!
 
Share this answer
 
v2
Comments
Mohd Arif Khan 23-Sep-13 4:10am    
it is giving this error
the best overloaded method match for 'string.IsNullOrEmpty(string)' has some invalid arguments
Guptha Ch 23-Sep-13 4:18am    
Try this instead of string.IsNullOrEmpty(Eval("ImgName"))

string.IsNullOrEmpty(Convert.ToString(Eval("ImgName")))
Mohd Arif Khan 23-Sep-13 4:23am    
i have tried it before you telling bro
Guptha Ch 23-Sep-13 4:26am    
It worked or not?
Mohd Arif Khan 23-Sep-13 4:27am    
nope

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