alenan2013 alenan2013 - 19 days ago 6
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>
<div class="dnnFormItem dnnFormShort">
<div>
<label><span>
<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>
<%#Eval("description")%>
</div>


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.

Answer

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()) %>'>
    <div>
        <label>
            <span>
                <asp:Label ID="lblSubQuestionLabel" runat="server"><%#Eval("tocht_id")%>&nbsp;<%#Eval("naam_tocht")%></asp:Label></span></label>
    </div>
    <asp:TextBox runat="server" TextMode="MultiLine" ID="txtSubQuestionBox"></asp:TextBox>
    <%#Eval("naam_tocht")%>
</asp:Panel>