ASP.NET AjaxControlToolkit.ComboBox 不显示其项目

ASP.NET AjaxControlToolkit.ComboBox does not show its items

我有一个 ASP.NET 应用程序,我使用 AjaxControl 工具包 组合框 动态创建多个 组合框 =27=]。所有 组合框 都填满了数据,但有些不显示数据。 这是我的代码:

cbo = new AjaxControlToolkit.ComboBox();

cbo.ID = string.Format(CultureInfo.GetCultureInfo("fr-FR"), "cbo{0}", RemoveSpecialCharacters(filter.Key)); // filter.key is the name of the combo
            cbo.AutoCompleteMode = AjaxControlToolkit.ComboBoxAutoCompleteMode.SuggestAppend;
            cbo.AutoPostBack = true;
            cbo.Visible = true;
            cbo.MaxLength = 500;

cbo.DataSource = GetFilterData2(requestId, filter.Key); // loads the data source with a list<string>
            cbo.DataBind();
            cbo.ItemInserted += this.CboItemInserted;
            this.cboFilters.Add(cbo);
            li.Controls.Add(cbo); // combo is added to the list item

当我用 Chrome 检查我的 HTML 页面时,我得到了有效的组合:

<ul id="MainContent_cboScanner_cboScanner_OptionList" class="ajax__combobox_itemlist" style="visibility: hidden; z-index: 1000; overflow-x: hidden; overflow-y: auto; width: 213px; position: absolute; height: 464px; left: 334px; top: 242px; display: none;">

对于未显示其项目的那个:

<ul id="MainContent_cboEnvironnement_cboEnvironnement_OptionList" class="ajax__combobox_itemlist" style="display:none;visibility:hidden;">

为什么 AjaxControlToolkit 组合框尽管有它们却不显示它的项目?

Id 中有 space 的错误文本框之后的所有组合框均未显示其项目。 我在所有文本框上添加了删除特殊字符方法,问题就解决了。

这是我添加的:

txt = new TextBox();
txt.ID = string.Format(CultureInfo.GetCultureInfo("fr-FR"), "txt{0}", RemoveSpecialCharacters(filter.Key));

这是我的方法:

private static string RemoveSpecialCharacters(string mystring)
{
  return mystring.Trim().Replace(' ', '_').Replace("'", "_").Replace("(", string.Empty).Replace(")", string.Empty).Replace("/", string.Empty).Replace(@"\", string.Empty);
}