how to do localization culture on radmenu coming from sitemap

6 posts, 0 answers
  1. Vaibhav
    Vaibhav avatar
    15 posts
    Member since:
    Feb 2014

    Posted 25 Feb 2014 Link to this post


    I have a RadMenu which is getting populated from a sitemap 
    I want to convert the text of menu based upon culture set from the language dropdown .

    Could any one help me on this , how to achieve this with small piece of code.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Feb 2014 in reply to Vaibhav Link to this post

    Hi Vaibhav,

    Please try the following c# code snippet to change the Text of The RadMenuItem.

    protected void RadDropDownList1_SelectedIndexChanged(object sender, DropDownListEventArgs e)
        if (e.Text == "Change") //your condition
            //accessing the menu item
            RadMenuItem menu = RadMenu1.FindItemByText("Home");
            //changing the text
            menu.Text = "Change";


  3. Vaibhav
    Vaibhav avatar
    15 posts
    Member since:
    Feb 2014

    Posted 25 Feb 2014 in reply to Shinu Link to this post

    Hi Shinu,

    As i mentioned my RadMenu is coming from the sitemap.
    So i dont have RadMenu1.FindItemByText("Home"); as its generated at runtime..and same goes with the submenu.

    One more thing here , I dont have a dropdown for language change, its a rad menu item with item template in it. Item template contain the anchor <a> tag's , if you remember from my last post. so need a work around here also.

    I want to make it completely independent of hard codding.
     For eg- If my site map gets another node or some sub node, then my menu automatically handles that , similarly i want to create some function for localization culture.

    And one more problem with your solution is ->
    Even if i get the elementbyText once i change the value of it from one language to another, then from changing it to the 3rd language , i wont find the menu item, as it will look for the text ie form the first language (Home), and all the menu items are in 2nd language say french.

    1)Searching for Home to convert from English to french- Found
    2)Converted to HomeFrnech
    3)searcing for Home again to change the language from french to german -> cant find because it does not exist. as the menu is changed from Home to HomeFrench

    Any other suggestion any one.....

  4. Boyan Dimitrov
    Boyan Dimitrov avatar
    2062 posts

    Posted 28 Feb 2014 Link to this post


    An easy and convenient way to avoid hard-coding in this code implementation would be to use the RadMenu ItemDataBound event. This event is fired for each menu item and you are able to access the current site map node in the e.Item.DataItem and cast that object to site map node. As far as I understand you have a drop-down that shows the current language preference so based on that value you are absolutely able to control the menu item text. So you can define your french translation for each site map node as a custom attribute. In the attached example the site map node with title "Home" has a custom attribute "frenchValue". In the RadMenu1_ItemDataBound event handler is shown how to access that custom value and set the current menu item's text value to that value.

    Alternative way would be on Page_Init to determine which language preference is selected and load different site map file. In the code snippet is shown how you can load a french site map file if the current language preference is french.
    //code behind
    protected void Page_Init(object sender, EventArgs e)
           if (//current language preference is set to french)
               SiteMap1.SiteMapFile = "you french language site map file";
               RadMenu1.DataSource = SiteMap1;

    In this case you will not need to use the RadMenu ItemDataBound handler.

    Boyan Dimitrov
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  5. Terry
    Terry avatar
    2 posts
    Member since:
    Aug 2012

    Posted 12 Mar 2015 Link to this post

    Hi Boyan,

    Can you go one step further on this and access a sitemap custom attribute from client-side? When I attempt to access a custom attribute from client-side, I get an "undefined" error. Here's what I am doing:

    <siteMapNode title="Maps" url="" roles="*" mapnum="2" />
    var item = eventArgs.get_item();
    var mapnum = item.get_attributes().getAttribute("mapnum");

    Thanks for your help,


  6. Hristo Valyavicharski
    Hristo Valyavicharski avatar
    975 posts

    Posted 17 Mar 2015 Link to this post

    Hi Terry,

    The item attribute is not set in ItemDataBound event. Please look at this help article:

    you need something like this:

    protected void RadMenu1_ItemDataBound(object sender,Telerik.Web.UI.RadMenuEventArgs e)
        DataRowView dataRow = (DataRowView)e.Item.DataItem;  
        e.Item.Attributes["Roles"] = dataRow["Roles"].ToString();
        e.Item.ToolTip = e.Item.Attributes["Roles"];

    Hristo Valyavicharski

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top