Who needs it.
The code to replace in "EditableDropDownList.cs" to use both the DataTextField DataValueField of the DropDownList. Not only does the DataTextField.
Example: from ["Hello","Ciao"] to [{value:"en-US", label:"Hello"}, {value:"it-IT", label:"Ciao"}]
protected override void Render(HtmlTextWriter writer)
{
if (Visible)
{
string style = (Width.Value > 0) ? string.Format(@" style=""width: {0}; ", Width) : string.Empty;
if (Style.Count > 0)
{
if (string.IsNullOrEmpty(style)) style = @" style=""";
foreach (string key in Style.Keys)
{
style += string.Format("{0}: {1}; ", key, Style[key]);
}
}
if (!string.IsNullOrEmpty(style)) style = style.TrimEnd() + @"""";
if (Items.Count > 0 && Enabled)
{
string css = string.Format(@"class=""ui-widget ui-widget-content ui-corner-left{0}""", (string.IsNullOrWhiteSpace(CssClass)) ? string.Empty : string.Format(@" {0}", CssClass));
List<string[]> dropDownItems = new List<string[]>();
foreach (ListItem item in Items)
{
dropDownItems.Add(new string[]{item.Value, item.Text});
}
string userSelections = CreateJavascriptArray(dropDownItems);
string tabIndex = (TabIndex > 0) ? string.Format(@" tabindex=""{0}"" ", TabIndex) : string.Empty;
string customAttributes = GetCustomAttributes();
string baseID = ClientID;
string markup = string.Format(@"<input type=""text"" value=""{0}"" id=""{1}"" name=""{1}"" {2}{3}{4}{5}/>", Text, baseID, css, style, tabIndex, customAttributes);
writer.Write(markup);
string listID = string.Format("{0}_list", ClientID);
string script = string.Format(@"$(""#{0}"").combobox( {{source: {1}, name: ""{2}"", autopostback: {3}, autoselectFirstItem: {4}}} );", baseID, userSelections, listID, (AutoPostBack || OnClick != null).ToString().ToLower(), AutoselectFirstItem.ToString().ToLower());
if (_setFocus)
{
script += string.Format("\n$(\"#{0}\").focus();", listID);
}
if (ScriptManager.GetCurrent(this.Page) != null)
ScriptManager.RegisterStartupScript(this, this.GetType(), "init" + ClientID, script, true);
else
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "init" + ClientID, script, true);
}
else
{
string css = string.Format(@"class=""ui-widget ui-widget-content ui-corner-left ui-corner-right{0}""", (string.IsNullOrWhiteSpace(CssClass)) ? string.Empty : string.Format(@" {0}", CssClass));
string disabled = (Enabled == true) ? string.Empty : @" disabled=""true""";
string markup = string.Format(@"<input type=""text"" value=""{0}"" id=""{1}"" name=""{1}"" {2}{3}{4}/>", Text, ClientID, css, style, disabled);
writer.Write(markup);
}
}
}
and
private string CreateJavascriptArray(List<string[]> values)
{
if (values == null || values.Count == 0)
return string.Empty;
if (Sorted)
{
values.Sort((k, v) => String.Compare(k[0], v[0]));
}
string data = "[";
string comma = string.Empty;
Dictionary<string, string> previousValues = new Dictionary<string, string>();
foreach (string[] s in values)
{
if (!string.IsNullOrEmpty(s[0]) && !previousValues.ContainsKey(s[0]))
{
data += comma + @"{value:""" + s[0].Replace(@"""", @"\""") + @""","
+ @"label:""" + s[1].Replace(@"""", @"\""") + @"""}";
if (string.IsNullOrEmpty(comma))
comma = ",";
previousValues.Add(s[0], s[1]);
}
}
data += "]";
return data;
}
|