Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > multi-language website with DropDownList selection View modes: 
User avatar
Member
Member
rafik4000-hotmail - 2/12/2011 11:56:52 AM
   
multi-language website with DropDownList selection
Hi,

I followed the instruction of making multi-language website with DropDownList selection
(with flag) but it tell me ListItem it don't recognize and if possible add a reference.
So I don't what I have to change to make it happen.

I followed the instruction of this poster:

http://devnet.kentico.com/Forums.aspx?forumid=45&threadid=15816

I did a clone of the webpart of Language selection with flags
and trying to change the codes behind but as I told before it don't recognize the listitem.

My best regards

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 2/21/2011 2:39:35 AM
   
RE:multi-language website with DropDownList selection
Hello,

Have you used the exact code Ivana provided? Could you please post here your webpart code?

Thank you in advance.

Best regards
Ondrej Vasil

User avatar
Member
Member
rafik4000-hotmail - 2/23/2011 10:29:16 AM
   
RE:multi-language website with DropDownList selection
Hi,

in Web part code in "languageselectionwithflags1.ascx"

<asp:Literal runat="server" ID="ltrDivOpen" EnableViewState="false" />
<asp:DropDownList OnSelectedIndexChanged="language_change" ID="DropDownList1"
runat="server" style="height: 22px" AutoPostBack="true"/>
<asp:Literal runat="server" ID="ltrDivClose" EnableViewState="false" />


in Web part code in "languageselectionwithflags1.ascx.cs"

using System;
using System.Data;
using System.IO;
using System.Web.Caching;

using CMS.PortalControls;
using CMS.GlobalHelper;
using CMS.CMSHelper;
using CMS.SiteProvider;

public partial class CMSWebParts_General_languageselectionwithflags : CMSAbstractWebPart
{
private string mLayoutSeparator = " ";
private string imgFlagIcon = "";
public string selectionClass = "";

#region "Public properties"

/// <summary>
/// Gets or sets the display layout
/// </summary>
public string DisplayLayout
{
get
{
return ValidationHelper.GetString(GetValue("DisplayLayout"), "");
}
set
{
SetValue("DisplayLayout", value);
mLayoutSeparator = value.ToLower() == "vertical" ? "<br />" : " ";
}
}


protected void language_change(object sender, EventArgs e)
{
UrlHelper.Redirect(DropDownList1.SelectedValue);
}

/// <summary>
/// Gets or sets the value that indicates whether the link for current culture should be hidden
/// </summary>
public bool HideCurrentCulture
{
get
{
return ValidationHelper.GetBoolean(GetValue("HideCurrentCulture"), false);
}
set
{
SetValue("HideCurrentCulture", value);
}
}


/// <summary>
/// Gets or sets the value than indicates whether culture names are displayed
/// </summary>
public bool ShowCultureNames
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowCultureNames"), true);
}
set
{
SetValue("ShowCultureNames", value);
}
}


/// <summary>
/// Gets or sets the separator between items
/// </summary>
public string Separator
{
get
{
return ValidationHelper.GetString(GetValue("Separator"), "");
}
set
{
SetValue("Separator", value);
}
}

#endregion


/// <summary>
/// Content loaded event handler
/// </summary>
public override void OnContentLoaded()
{
base.OnContentLoaded();
SetupControl();
}


/// <summary>
/// Reloads data for partial caching
/// </summary>
public override void ReloadData()
{
base.ReloadData();
SetupControl();
}



/// <summary>
/// Initializes the control properties
/// </summary>
protected void SetupControl()
{
if (StopProcessing)
{
// Do nothing
}
else
{
mLayoutSeparator = DisplayLayout.ToLower() == "vertical" ? "<br />" : " ";

DataSet ds = null;

// Try to get data from cache
using (CachedSection<DataSet> cs = new CachedSection<DataSet>(ref ds, this.CacheMinutes, true, this.CacheItemName, "languageselection", CMSContext.CurrentSiteName))
{
if (cs.LoadData)
{
// Get the data
ds = CultureInfoProvider.GetSiteCultures(CMSContext.CurrentSiteName);

// Save to the cache
if (cs.Cached)
{
cs.CacheDependency = CacheHelper.GetCacheDependency(new string[] { "cms.culturesite|all" });
cs.Data = ds;
}
}
}




if (!DataHelper.DataSourceIsEmpty(ds) && (ds.Tables[0].Rows.Count > 1))
{
// Build current URL
string url = UrlHelper.CurrentURL;
url = UrlHelper.RemoveParameterFromUrl(url, UrlHelper.LanguageParameterName);
url = UrlHelper.RemoveParameterFromUrl(url, UrlHelper.AliasPathParameterName);


string ltlHyperlinks = "";
int count = 0;
int rows = ds.Tables[0].Rows.Count;


foreach (DataRow dr in ds.Tables[0].Rows)
{
string cultureCode = dr["CultureCode"].ToString();
string cultureShortName = dr["CultureShortName"].ToString();
if (!((HideCurrentCulture) && (String.Compare(CMSContext.CurrentDocument.DocumentCulture, cultureCode, true) == 0)))
{
// Add flag icon before the link text
ltlHyperlinks = HTMLHelper.HTMLEncode(UrlHelper.AddParameterToUrl(url, UrlHelper.LanguageParameterName, cultureCode));

// Add language to dropdown list
DropDownList1.Items.Add(new ListItem(HTMLHelper.HTMLEncode(cultureShortName), ltlHyperlinks));

// Set surrounding div css class
selectionClass = "languageSelectionWithCultures";
}
count++;
}
// Set item in DropDownList1 to Selected
DropDownList1.Items.FindByValue(UrlHelper.AddParameterToUrl(url, UrlHelper.LanguageParameterName, CookieHelper.GetValue("CMSPreferredCulture"))).Selected = true;
}
else
{
// Hide if less than two cultures
Visible = false;
}

if (string.IsNullOrEmpty(selectionClass))
{
ltrDivOpen.Text = "<div>";
}
else
{
ltrDivOpen.Text = "<div class=\"" + selectionClass + "\">";
}
ltrDivClose.Text = "</div>";

// Check if RTL hack must be applied
if (CultureHelper.IsPreferredCultureRTL())
{
ltrDivOpen.Text += "<span style=\"visibility:hidden;\">a</span>";
}
}
}


/// <summary>
/// Clears the cached items
/// </summary>
public override void ClearCache()
{
string useCacheItemName = DataHelper.GetNotEmpty(CacheItemName, CMSContext.BaseCacheKey + "|" + Context.Request.Url + "|" + ClientID);

CacheHelper.ClearCache(useCacheItemName);
}


}


The error I get on ListItem "Error 3 The type or namespace name 'ListItem' could not be found (are you missing a using directive or an assembly reference?)"

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 3/9/2011 12:56:10 AM
   
RE:multi-language website with DropDownList selection
Hello,

You will need to tell the system where to look for when working with the ListItem. You can do that by providing appropriate namespace either directly in the foreach loop in the SetupControl method:

System.Web.UI.WebControls.ListItem

or by adding the following line at the beginning:

using System.Web.UI.WebControls;

Best regards
Ondrej Vasil

User avatar
Member
Member
rafik4000-hotmail - 3/9/2011 11:58:29 PM
   
RE:multi-language website with DropDownList selection
It work great

I would like to thank you for your help and I suggest to make it as webpart for the next kentico CMS 6.0 it is useful

Thank you

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 3/10/2011 12:53:55 AM
   
RE:multi-language website with DropDownList selection
Hello,

I'm glad it worked. I'll pass this requirement to our product manager. He will consider whether it will be added within the next versions. Please feel free to raise a vote on our voting portal: http://kentico.uservoice.com/forums/33767-general-suggestions

Best regards
Ondrej Vasil