views:

426

answers:

2

Hi,

I am trying to access the current 'active' top level node from a sitemap repeater from outside of the ASP.NET repeater used to render it, this is for CSS styling purposes as I want to place the child nodes on the subsequent row with different styling horizontally. At present I have the following code which I can't get to display correctly using CSS.

<asp:SiteMapDataSource ID="topNavLevel" runat="server" ShowStartingNode="false" />
 <asp:Repeater runat="server" ID="rptParent" DataSourceID="topNavLevel">
  <HeaderTemplate><ul id="lawMenu" class="topMenu"></HeaderTemplate>
  <ItemTemplate>
   <li>
    <asp:HyperLink runat="server" ID="parentLink" NavigateUrl='<%# Eval("Url") %>'><span class="t"><%# Eval("Title") %></span><span class="l"></span><span class="r"></span></asp:HyperLink>
    <asp:Repeater ID="rptChild" runat="server" DataSource='<%# ((SiteMapNode) Container.DataItem).ChildNodes %>'>
     <HeaderTemplate>
       <ul>
     </HeaderTemplate>
     <ItemTemplate>
      <li>
       <asp:HyperLink ID="childLink" runat="server" NavigateUrl='<%# Eval("Url") %>'><span class="t"><%# Eval("Title") %></span><span class="l"></span><span class="r"></span></asp:HyperLink>
      </li>
     </ItemTemplate>
     <FooterTemplate>
       </ul>
     </FooterTemplate>
    </asp:Repeater>
   </li>
  </ItemTemplate>
  <FooterTemplate>
   </ul></FooterTemplate>
 </asp:Repeater>

I would like to display the child nodes on the next light blue element which I can do perfectly well from a seperate div if this was not rendered using a child repeater. In the image below Blog and Services are top level nodes and their subseqent nodes (2 for each) should be displayed on the light-blue row below. Is this possible?

Thanks.

http://yfrog.com/13captureayp

A: 

To get the parent repeaters DataItem as if you weren't inside your child repeater:

<%# DataBinder.Eval(((System.Web.UI.WebControls.RepeaterItem)Container.Parent.Parent).DataItem, "Property") %>
Nick Craver
Hi Nick, can you expand on this based on the above scenario? I need to list the child elements of the current node (parent) repeater. This needs to be in the form of a separate div element with some code to create the new child repeater within. Thanks for your help.
A: 

I have solved this now. For anyone else coming across this post here's the solution:

<asp:SiteMapDataSource ID="topNavLevel" runat="server" ShowStartingNode="false" />
            <asp:Repeater runat="server" ID="rptParent" DataSourceID="topNavLevel">
                <HeaderTemplate>
                    <ul id="lawmenu" class="law-menu">
                </HeaderTemplate>
                <ItemTemplate>
                    <li>
                        <asp:HyperLink runat="server" ID="parentLink" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
                    </li>
                </ItemTemplate>
                <FooterTemplate>
                    </ul>
      </FooterTemplate>
            </asp:Repeater>
            </div>
            <div class="law-nav_nav2">
            <asp:SiteMapDataSource ID="secondNavLevel" runat="server" ShowStartingNode="false" StartingNodeOffset="1" />
                <asp:Repeater ID="rptChild" runat="server" DataSourceID="secondNavLevel">
                            <HeaderTemplate>
                                <ul class="law-menu_nav2"style="z-index:100">
                            </HeaderTemplate>
                            <ItemTemplate>
                            <li>
                            <asp:HyperLink ID="childLink" runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
                            </li>
                            </ItemTemplate>
                            <FooterTemplate>
                                </ul>
                            </FooterTemplate>
                        </asp:Repeater>
            </div>

The HeaderTemplate takes care of the list container styling then the repeater items are listed out one at a time with an offset of 1 for the current node. This looks easy based on what I have seen around the net, I'm just fairly new to some elements of ASP.NET :) Thanks.