How to create Language Switcher in ASPX Master page?

Gary Chau asked on January 20, 2019 12:44

Followed https://devnet.kentico.com/questions/language-selector-in-aspx-page, but the data source of the Language data source is null.

Anyone can help? Thanks.

Correct Answer

Eric Dugre answered on January 22, 2019 22:01

Gary,

I was able to get this working by looking at the built-in web part for inspiration (~\CMSWebParts\DataSources\LanguageDataSource.ascx.cs). This is what I used in the ASCX:

<cms:LanguageDataSource runat="server" ID="langs" />
<cms:BasicRepeater runat="server" ID="rep">
     <ItemTemplate>
           <%# Eval("CultureName") %> <%# Eval("Url") %><br/>
     </ItemTemplate>
</cms:BasicRepeater>

And in the code behind:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    langs.Node = DocumentContext.CurrentDocument;
    List<DocumentCultureUrl> ds = langs.DataSource as List<DocumentCultureUrl>;
    rep.DataSource = ds.OrderBy(x => x.CultureName).ToList();
    rep.DataBind();
}
1 votesVote for this answer Unmark Correct answer

Recent Answers


Gary Chau answered on January 23, 2019 03:19

Thanks, Eric

Your way is working and saved my day

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.