简体   繁体   中英

how to access a header template in c#

I have a template:

<asp:Repeater ID="litFolder" runat="server" OnItemDataBound="litFolder_ItemDataBound">
    <HeaderTemplate>
        <ul class="test" id="currentLink">
    </HeaderTemplate>
    <ItemTemplate>
        <div class="leftNav">
            <li>
               <asp:HyperLink ID="innerHyperLink" runat="server"></asp:HyperLink>
            </li>
        </div>
    </ItemTemplate>
    <FooterTemplate>
        </ul>
    </FooterTemplate>
</asp:Repeater>

and I'm trying to set the to display block when a link is selected. I can set the link to display block, but how do I set the ul to display block ( only using C# )

    protected void litFolder_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // if the child from the first repeater has children, it will grab them here
        Item innerItem = (Item)e.Item.DataItem;

        if (innerItem != null)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                // this creates a link to the page in sitecore once clicked
                HyperLink topNavigation = (HyperLink)e.Item.FindControl("innerHyperLink");
                topNavigation.NavigateUrl = LinkManager.GetItemUrl(innerItem);
                topNavigation.Text = innerItem["Title"];

                if (topNavigation != null) {
                   //this is where I think I need to define the ul to display block
                }
            }
        }
    }

I need to make sure that the current link sets the ul that it is in and not all the ul's with the class test.

In order to prevent the Ul from being broken, place the <div class="leftNav"> inside the <li> as shown below:

<asp:Repeater ID="litFolder" runat="server" OnItemDataBound="litFolder_ItemDataBound">
<HeaderTemplate>
    <ul class="test" id="currentLink">
</HeaderTemplate>
<ItemTemplate>
        <li>
         <div class="leftNav">
           <asp:HyperLink ID="innerHyperLink" runat="server"></asp:HyperLink>
         </div>
        </li>
</ItemTemplate>
<FooterTemplate>
    </ul>
</FooterTemplate>

To set the display block style, you can find the control based on the ID, then set the style to it.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM