Problem with dynamically created RadMenu

3 posts, 1 answers
  1. Evelyne Schreiner
    Evelyne Schreiner avatar
    20 posts
    Member since:
    Sep 2009

    Posted 21 Jun 2010 Link to this post

    Hello,

    I'm new to Telerik world and creating a RadMenu like this:
           <telerik:RadSiteMap runat="server"   
            ID="RadSiteMapPublications" DataSourceID="RadSiteMapDataPublications" Width="640px">  
            <LevelSettings> 
            <telerik:SiteMapLevelSetting Level="0" ListLayout-RepeatColumns="4" ListLayout-RepeatDirection="Horizontal"></telerik:SiteMapLevelSetting> 
            </LevelSettings> 
            </telerik:RadSiteMap> 
            <telerik:RadSiteMapDataSource ID="RadSiteMapDataPublications" SiteMapFile="~/web.sitemap" ShowStartingNode="false" StartingNodeUrl="http://saratoga/lr/pages/default.aspx?id=2036" runat="server" /> 

    which is working fine.

    Now, trying to do the same dynamically in the code-behind, it doesn't work. Here is my code:
            Dim myDataSource As New RadSiteMapDataSource  
            myDataSource.SiteMapFile = "~/web.sitemap" 
            myDataSource.ShowStartingNode = False 
            myDataSource.StartingNodeUrl = "http://saratoga/lr/pages/default.aspx?id=2017" 
     
            Dim mySiteMap As New RadSiteMap  
            mySiteMap.Width = 640 
            mySiteMap.Height = 200 
            mySiteMap.DataSource = myDataSource 
     
            Dim mySetting As New SiteMapLevelSetting  
            mySetting.Level = 0 
            mySetting.ListLayout.RepeatColumns = 4 
            mySetting.ListLayout.RepeatDirection = SiteMapRepeatDirection.Horizontal  
     
            mySiteMap.LevelSettings.Add(mySetting)  
     
            myLabel.Controls.Add(mySiteMap) 

    "myLabel" is a label on my test page.

    I suppose the problem is with the levelSettings, but I don't see where is the error. Could anyone help, please ?
  2. Answer
    Veronica
    Admin
    Veronica avatar
    1213 posts

    Posted 22 Jun 2010 Link to this post

    Hi Evelyne Schreiner,

    You'll have to add the controls (RadSiteMapDataSource and RadSiteMap) in the Page.Form to be able to create them dynamically:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
           Dim myDataSource As New RadSiteMapDataSource()
           myDataSource.ID = "RadSiteMapPublications"
           myDataSource.SiteMapFile = "web.sitemap"
           myDataSource.ShowStartingNode = True
           Me.Page.Form.Controls.Add(myDataSource)
           Dim mySiteMap As New RadSiteMap()
           mySiteMap.Width = 640
           mySiteMap.Height = 200
           mySiteMap.DataSourceID = myDataSource.ID
           Dim mySetting As New SiteMapLevelSetting()
           mySetting.Level = 0
           mySetting.ListLayout.RepeatColumns = 4
           mySetting.ListLayout.RepeatDirection = SiteMapRepeatDirection.Horizontal
           mySiteMap.LevelSettings.Add(mySetting)
           Me.Page.Form.Controls.Add(mySiteMap)
       End Sub

    Find the full code in the attached .zip file.

    Hope this helps.

    Greetings,
    Veronica Milcheva
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Evelyne Schreiner
    Evelyne Schreiner avatar
    20 posts
    Member since:
    Sep 2009

    Posted 23 Jun 2010 Link to this post

    Perfect. Thank you very much, Veronica !
Back to Top