This is a migrated thread and some comments may be shown as answers.

Problem with dynamically created RadMenu

2 Answers 130 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Evelyne Schreiner
Top achievements
Rank 1
Evelyne Schreiner asked on 21 Jun 2010, 10:35 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Veronica
Telerik team
answered on 22 Jun 2010, 05:32 PM
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
0
Evelyne Schreiner
Top achievements
Rank 1
answered on 23 Jun 2010, 12:16 PM
Perfect. Thank you very much, Veronica !
Tags
Menu
Asked by
Evelyne Schreiner
Top achievements
Rank 1
Answers by
Veronica
Telerik team
Evelyne Schreiner
Top achievements
Rank 1
Share this question
or