ozkank
ozkank

Reputation: 1462

using nested repeater in asp.net

I want to do a custom menu with asp.net repeater. I'm getting my data SiteMap.RootNode.ChildNodes and it's childnodes.

asp.net :

<asp:Repeater runat="server" ID="rep1" OnItemDataBound="rpt1_ItemDataBound">
    <HeaderTemplate>
        <ul>
    </HeaderTemplate>
    <ItemTemplate>
        <li class="links">
            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>' Text='<%# Eval("Title") %>'></asp:HyperLink>
        </li>
        <%--<asp:Repeater ID="rep2" runat="server">                                     
        </asp:Repeater>--%>
    </ItemTemplate>
    <FooterTemplate>
        </ul>
    </FooterTemplate>
</asp:Repeater>

C#

protected void Page_Load(object sender, EventArgs e)
{
      rep1.DataSource = SiteMap.RootNode.ChildNodes;
      rep1.DataBind();
}

protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
}

How to do this? Please help me.

edit : enter image description here

Upvotes: 1

Views: 2410

Answers (1)

Anderson Pimentel
Anderson Pimentel

Reputation: 5757

If you have only two hierarchy levels, you are halfway there: use the ItemDataBound event to set the DataSource for the inner repeater: ((Repeater)FindControl('rep2')).DataSource = <proper data>;

If you have multiple/unknown hierarchy levels, the only way would be creating them all from code behind. You could use a Panel as a container, create the repeaters dinamically and add the parent one to the panel, like: Panel1.Controls.Add(rep1);

Upvotes: 2

Related Questions