Find html anchor inside repeater with dynamic data and then change ID

Last post 11-07-2009 7:56 PM by cynicalcoder. 2 replies.

Sort Posts:

  • Find html anchor inside repeater with dynamic data and then change ID

    11-05-2009, 4:25 PM
    • Member
      1 point Member
    • cynicalcoder
    • Member since 11-05-2009, 4:12 PM
    • Posts 2

    Hello

    I have a master page that uses a repeater to create html anchors for the main navigation menu.  I also have some css that controls the display.  The anchors are databound from a web.sitemap file. 

    I also have exposed a property on the master page that specifies which anchor is supposed to be highlighted in the navigation menu.  Content forms assign value to this property.

    Here are the relevant snippets:

                <div class="menu">
                    <ul>
                        <li>
                            <asp:HyperLink runat="server" ID="lnkHome" NavigateUrl="~/Default.aspx">Home</asp:HyperLink></li>
                        <asp:Repeater runat="server" ID="parentMenu" DataSourceID="mainSiteMap" EnableViewState="false">
                            <ItemTemplate>
                                <li>
                                    <asp:HyperLink runat="server" id="parentLink" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
                                    <asp:Repeater ID="childMenu" runat="server" DataSource="<%# CType(Container.DataItem, SiteMapNode).ChildNodes %>">
                                        <HeaderTemplate>
                                            <ul>
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <li>
                                                <asp:HyperLink runat="server" id="childLink" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink></li>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            </ul>
                                        </FooterTemplate>
                                    </asp:Repeater>
                                </li>
                            </ItemTemplate>
                        </asp:Repeater>
                    </ul>
                    <asp:SiteMapDataSource ID="mainSiteMap" runat="server" ShowStartingNode="false" />
                </div>


     

     Private Sub parentMenu_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles parentMenu.ItemDataBound
    
            If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
    
                If CType(e.Item.DataItem, SiteMapNode).Title = ActiveMenuSelection Then
                    ' find the html anchor and modify attributes to trigger CSS changes
                Else
                    lnkHome.ID = "current"
    
                End If
    
            End If
    
        End Sub
        


     

     

    What happens is I successfully match the ActiveMenuSelection property to the item_databound argument, but from there I am a little fuzzy on finding the specific control I want to modify. 

     

    Has anyone ever tried something like this? 

     

    I know that I could probably use an <asp:Menu /> control, but if there is a solution to the above, that would be better for my purposes.

     

    Thanks in advance.

     

    CC

     

  • Re: Find html anchor inside repeater with dynamic data and then change ID

    11-06-2009, 12:31 AM
    Answer
    • Contributor
      2,044 point Contributor
    • vipuldonga
    • Member since 02-10-2009, 11:18 AM
    • Ahmedabad
    • Posts 360

    hi,

    if you find "parentLink" anchor tag you can used this way

    HtmlAnchor parentLink = e.Item.FindControl("parentLink") as HtmlAncho;

    now you can do any thing with this "parentLink"

    if you want to find "childLink" in the nestad repeater you can first find child repeater then you can do same way as above

    Thanks & Regards
    Vipul Donga

    Mark it as an answer, if it helped

    if (MyAnswer)
    MarkAsAnswer();
  • Re: Find html anchor inside repeater with dynamic data and then change ID

    11-07-2009, 7:56 PM
    • Member
      1 point Member
    • cynicalcoder
    • Member since 11-05-2009, 4:12 PM
    • Posts 2

    /smacks forehead

     

    I think I was looking at it too long - thanks 

Page 1 of 1 (3 items)