alenan2013 alenan2013 - 7 months ago 41
ASP.NET (C#) Question

How to hide a div in the Repeater

I have been working on VB ASP.NET site, Visual Studio 2012 Express for Web. I have a Repeater with two div tags and css classes .dnnFormLabel and .dnnFormItem. Here is a part code in the Repeater:

<div class="dnnFormLabel dnnFormShort">
<asp:CheckBox runat="server" ID="chkSubQuestionBox" Text='<%#Eval("Label")%>' />
<div class="dnnFormItem dnnFormShort">
<asp:Label ID="lblSubQuestionLabel" runat="server"><%#Eval("Prefix")%>&nbsp;<%#Eval("Label")%></asp:Label></span></label></div>
<asp:TextBox runat="server" TextMode="MultiLine" ID="txtSubQuestionBox"></asp:TextBox>

I want to hide div with class .dnnFormItem when it doesn't have any content. For this, I tried with:

.dnnFormItem:empty {
display: none !important;

but it doesn't work. How can I do this? Thank you in advance for any help.


You can use a Panel for that and set the Visible property based on a column value from the dataset.

<asp:Panel ID="Panel1" runat="server" CssClass="dnnFormItem dnnFormShort" Visible='<%# !string.IsNullOrEmpty(Eval("columnToValidate").ToString()) %>'>
                <asp:Label ID="lblSubQuestionLabel" runat="server"><%#Eval("tocht_id")%>&nbsp;<%#Eval("naam_tocht")%></asp:Label></span></label>
    <asp:TextBox runat="server" TextMode="MultiLine" ID="txtSubQuestionBox"></asp:TextBox>