Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a datalist and a gridview that have item template field which contain image,
i want to not show image when its blank.(image.visible=false)
how can i do that?

ASP.NET
<asp:DataList ID="dlNews" runat="server"  CellPadding="4" 
                        ForeColor="#333333" Width="100%"  >
                        <AlternatingItemStyle BackColor="White" />
                        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                        <ItemStyle BackColor="#FFFBD6" ForeColor="#333333" />
                    <ItemTemplate>
                    <table width="100%" >
                    <tr>
                    <td>
                    <asp:Label ID="lblNewsTitle" runat="server" Text='<%# Eval("NewsTitle") %>' Font-Bold="True" Font-Size="Larger" Font-Names="Verdana"></asp:Label>
                    </td>
                    <td>
                    
                    </td>
                    </tr>
                    <tr>
                    <td  width="80%" valign="top">
                    <asp:Label ID="LblNewsText" runat="server" Text='<%# Eval("NewsText") %>'></asp:Label>
                    </td>
                    <td valign="middle"  width="20%">
                       
                                             
                    <asp:Image ID="imgNews" runat="server" 
                            ImageUrl='<%# GetThumbFilename(Eval("NewsImageUrl").ToString() ) %>'  
                             Visible="true" />
                    
                    </td>
                    </tr>
                    <tr>
                    <td>
                    <asp:Label ID="LblNewsDate" runat="server" Text='<%# Eval("NewsDate","<span dir=ltr>{0:yyyy/MM/dd}</span>") %>'></asp:Label>
                    </td>
                    </tr>
                    </table>
                     
                        
                                          
                      
                    </ItemTemplate>
                        <SelectedItemStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                    </asp:DataList>





and its my c# code

C#
private string imageUploadPath = "~/Uploads/NewsImages/";
protected string GetThumbFilename(string OriginalFilename)
{


        string thumbfilename =
                Path.GetFileNameWithoutExtension(OriginalFilename)
                + "_Thumb"
                + Path.GetExtension(OriginalFilename);

        return imageUploadPath + thumbfilename;



}



gridview is on another page,but use getthumbfilename as same as datalist.
Posted
Comments
Sinisa Hajnal 2-Mar-15 2:05am    
Put single pixel transparent image into the image and it will be as if it isn't there :)

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