Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two repeaters nested in my application which is working fine. I would love to display the footer if the child repeater is empty. Due to my code my long html, i will just drop a sample of what my html looks like and post my full code for better understanding. Everything works fine though unless when the child repeater is empty i want to display the footer message

What I have tried:

<asp:Repeater ID="ProductRepeater" runat="server" OnItemDataBound="ProductRepeater_ItemDataBound">
        <HeaderTemplate></HeaderTemplate>
        <ItemTemplate>
           <table>
<tr>
<td>
<%#Eval("Name")%>
</td>
<tr>
</table>
<pre> <asp:Repeater ID="ChildRepeater" runat="server">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<table>
<tr>
<td>
<%#Eval("Description")%>
<td>
</tr>
<table>
</itemTemplate>
<pre><FooterTemplate>
                                        <div>
                                            <h5><asp:Label ID="lblDefaultMessage" runat="server" Text="This is empty. " Visible="false" ForeColor="Red" Font-Size="Large">
                                                  </asp:Label>
                                                </h5>
                                                </div>
                                            
                                        </FooterTemplate>







<protected void ProductRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                string category = "Value"
                Repeater rptRelated = e.Item.FindControl("ChildRepeater") as Repeater;
                rptRelated.DataSource = getChild(category);
                rptRelated.DataBind();
                if (rptRelated.Items.Count < 1)
                {
                    if (e.Item.ItemType == ListItemType.Footer)
                    {
                        Label lblDefaultMessage = (Label)e.Item.FindControl("lblDefaultMessage");
                        lblDefaultMessage.Visible = true;

                    } 
                }
                
            }
        }
Posted

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