views:

279

answers:

2

I want to create a three level menu, I have got a recursive function today that works with three levels. But the thing is how do i output the third lever? Using two repeaters i have managed to get a hold of the first two levels through the ChildNodes property. But that only gives me the second level. What if a want the third level? Example code below. How do i get the third level? :)

<asp:Repeater ID="FirstLevel" DataSourceID="SiteMapDataSource" runat="server" EnableViewState="false">
                <ItemTemplate>
                    <li class="top">
                        <a href='/About/<%#Eval("Title")%>.aspx' class="top_link"><span class="down"><%#Eval("Title")%></span><!--[if gte IE 7]><!--></a><!--<![endif]-->
                        <asp:Repeater runat="server" ID="SecondLevel" DataSource='<%#((SiteMapNode)Container.DataItem).ChildNodes%>'>
                            <HeaderTemplate><!--[if lte IE 6]><table><tr><td><![endif]--><ul class="sub"></HeaderTemplate>
                            <ItemTemplate>
                                <li>
                                    <a href='<%#((string)Eval("Url")).Replace("~", "")%>' style="text-align: left;"><%#Eval("Title")%></a>

                                    Third repeater here?

                                </li>
                            </ItemTemplate>
                            <FooterTemplate></ul><!--[if lte IE 6]></td></tr></table></a><![endif]--></FooterTemplate>
                        </asp:Repeater>
                    </li>
                </ItemTemplate>
            </asp:Repeater>
A: 

I would use the OnItemCreatedEvent of the repeater to register the OnItemDataBound event of each repeater and then bound the data accordingly. Is the asp:menu control not appropriate? Why repeaters?

FiveTools
A: 

I would create a custom server control and parse the sitemap recursively. This will give you more control of the rendering and allow you to specify additional custom attributes for the sitemap nodes.

Paulus E Kurniawan
This is already done, i have got a SiteMapProvider class that inherits from StaticSiteMapProvider and builds the sitemap recursively. But the problem is how do i render it with three levels? Doesn't the Menu control create awful tables and such? I think that is why it was dumped the first time :)
I was suggesting to create a custom server control, not a sitemap provider. For a simple sitemap, the ASP.NET Menu control will work fine. Use the CSS Friendly Adapters to render the menu as a list, http://cssfriendly.codeplex.com.
Paulus E Kurniawan