+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Dropdown list for language selection

Dropdown list for language selection

3 posts, 0 answered
  1. Leon Williams
    Leon Williams avatar
    20 posts
    Registered:
    18 Mar 2010
    10 Jun 2010
    Link to this post

    I am attempting to remove a language from the language bar. I am following the guide on the forums which suggests doing the following:

    <%@ Register Assembly="Telerik.Localization" Namespace="Telerik.Localization.WebControls" TagPrefix="lng" %>
    <lng:LanguageBar  ID="list1" runat="server">
    <LayoutTemplate>
    <lng:LanguageList CssClass="langList" ID="languageList" runat="server">
    </lng:LanguageList>
    </LayoutTemplate>
    </lng:LanguageBar>

    using Telerik.Localization.WebControls;
    LanguageList lngList = this.FindControlRecursive(list1, "languageList") as LanguageList;
    for(  int i = lngList.Items.Count-1 ; i >= 0 ; i-- )
    {
      ListItem li = lngList.Items[i];
      if (li.Value == "de")
      {
        lngList.Items.RemoveAt(i);
      }
    }

    private Control FindControlRecursive(Control root, string id)
    {
      if (root.ID == id)
      {
        return root;
      }
      foreach (Control c in root.Controls)
      {
        Control t = FindControlRecursive(c, id);
        if (t != null)
        {
          return t;
        }
      }
      return null;


    This seems to cause the dropdownlist languagebar to not render, and instead it appears as a couple of links.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Jun 2010
    Link to this post
    Hello Leon Williams,

    Use the code below 

    <%@ Register Assembly="Telerik.Localization" Namespace="Telerik.Localization.WebControls" TagPrefix="sf3" %>
      
        <sf3:LanguageBar ID="LangBar" runat="server">
            <LayoutTemplate>
                <asp:DropDownList ID="languageList" runat="server"></asp:DropDownList>
            </LayoutTemplate>
        </sf3:LanguageBar>


    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        var LanguageDropDownList = this.FindControlRecursive(LangBar, "languageList") as DropDownList;
        if (LanguageDropDownList != null)
        {
            for (int i = LanguageDropDownList.Items.Count - 1; i >= 0; i--)
            {
                ListItem li = LanguageDropDownList.Items[i];
                if (li.Value == "de")
                {
                    LanguageDropDownList.Items.RemoveAt(i);
                }
            }
        }
     }


    Greetings,
    Ivan Dimitrov
    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. Leon Williams
    Leon Williams avatar
    20 posts
    Registered:
    18 Mar 2010
    10 Jun 2010
    Link to this post
    Thanks!  It fixed the problem I was having.

    I appreciate your help!

    Leon
Register for webinar
3 posts, 0 answered