Click here to Skip to main content
14,420,468 members
Rate this:
Please Sign up or sign in to vote.
See more:
 <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<div class="carousel-item <%#GetActiveClass(Container.ItemIndex) %>">
<img id="image" src='data:photos/jpg;base64,<%# Eval("photos") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("photos")) : string.Empty %>' alt="image" height="" width="" />  
                                  
<asp:Label ID="lbl_eng" runat="server" Text='<%# Eval("news_eng") %>' Width="100%" />

<asp:Label ID="lbl_hindi" runat="server" Text='<%# Eval("news_hindi") %>' Width="100%" />
</div>
</ItemTemplate>
</asp:Repeater>


What I have tried:

The img control is not a asp:image, it is a simple html image control and want to hide the same if there is no photo in database save. Will be solved through Repeater dataitembound() method but not know how it is possible.


Please help...
Posted
Updated 23-Aug-19 1:58am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

If you're doing this on a row by row bases then you can add a "runat" tag to your img and set its visibility to false just like any other server-side component (it will be something like System.Web.UI.HtmlControls.HtmlElement in your code-behind). If the reason you don't want to do that is because it will change the "id" if your img, then that is a problem you are saving up for yourself later on....ids have to be unique so if you think you can use that "image" id in javascript then you can't.

If you really don't want to add runat to the img then wrap it in a PlaceHolder instead

<asp:PlaceHolder runat="server" ID="MyPlaceHolder">
<img .... />
</asp:PlaceHolder>


In your Repeater1_ItemDataBound even you can then set the placeholder's visibility to false if there is no image for that row.

https://asp-net-example.blogspot.com/2009/02/aspnet-placeholder-example-how-to-use.html
   
Comments
Maciej Los 23-Aug-19 7:02am
   
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100