Add SiteMap to Custom Links Dropdown

5 posts, 0 answers
  1. Sam Miller
    Sam Miller avatar
    6 posts
    Member since:
    Jan 2007

    Posted 24 Jan 2007 Link to this post

    Requirements

    r.a.d.controls version

    6.x - 7.x

    .NET version

    2.0

    Visual Studio version

    2005

    programming language

    C#

    browser support

    all browsers supported by r.a.d.controls


     
  2. PROJECT DESCRIPTION
    I needed a way to display all the links available on my client's sitemap in the links dropdown. 

    This is code to bind the "Custom Links" drop down in your editor to your site's sitemap provider, if you are using one. 

    <script runat="server">  
        protected override void OnLoad(EventArgs e)  
        {  
            base.OnLoad(e);  
            if (!IsPostBack)  
            {  
                editor1.Links.Clear();  
                BindLinks(editor1.Links, SiteMap.RootNode);  
            }  
        }  
     
        private void BindLinks(Link parentLink, SiteMapNode siteMapNode)  
        {  
            Link currentLink = new Link(siteMapNode.Title, siteMapNode.Url, "", siteMapNode.Description);  
            parentLink.Add(currentLink);  
            for (int i=0; i<siteMapNode.ChildNodes.Count; i++)  
            {  
                BindLinks(currentLink, siteMapNode.ChildNodes[i]);  
            }  
        }  
    </script> 

    <

    RadE:RadEditor ID="editor1" runat="server"></RadE:RadEditor>



    To run the example, just copy the attached aspx page in the root of your web site, having RadEditor in it, and load it in your browser.

    And bingo, you have the sitemap content in your Custom Links box.

    Enjoy!
  • Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 29 Jan 2007 Link to this post

    Hi Sam,

    Thank you for sharing your idea with us. We have updated your code and attached the new zip to your post.

    As a small token of gratitude for your code library solution we have added 1500 telerik points to your account.

    Best regards,
    Rumen
    the telerik team
  • Jason Miller
    Jason Miller avatar
    8 posts
    Member since:
    Oct 2006

    Posted 03 Mar 2007 Link to this post

    Nice example I had been doing this manually iterating through the node list.

    I converted your example to code behind in VB for anyone who needs it in VB instead.

    #Region "SET RAD EDITOR VALUES"

    Private Sub GetSiteMap()

    'Clear our links and set our sitemap

    RadEditor1.Links.Clear()

    'Recursively process our Sitemap into our RadEditor

    SetRadLinks(RadEditor1.Links, SiteMap.RootNode)

    End Sub

    Private Sub SetRadLinks(ByVal ParentLink As Telerik.WebControls.RadEditorUtils.Link, ByVal mySiteMapNode As SiteMapNode)

    Dim I As Int32 = 0

    Dim CurrentLink As Telerik.WebControls.RadEditorUtils.Link = New Telerik.WebControls.RadEditorUtils.Link(mySiteMapNode.Title, mySiteMapNode.Url, "", mySiteMapNode.Description)

    ParentLink.Add(CurrentLink)

    'Loop through our Child Links

    For I = 0 To (mySiteMapNode.ChildNodes.Count - 1)

    SetRadLinks(CurrentLink, mySiteMapNode.ChildNodes(I))

    Next

    End Sub

    #End Region

  • Petya
    Admin
    Petya avatar
    869 posts

    Posted 05 Mar 2007 Link to this post

    Hi,

    Thank you for being so active and sharing with the telerik community. As a small way to thank you, please find 500 points added to your account.

    Greetings,
    Petya
    the telerik team
  • George
    Admin
    George avatar
    859 posts

    Posted 19 Feb 2008 Link to this post

    Hi,

    Please, find the project updated with RadEditor "Prometheus" in the first post as well.

    Kind regards,
    George
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  • Back to Top