【发布时间】:2011-03-13 20:19:01
【问题描述】:
我正在使用 devexpress ASPxComboBox,但是我想知道如何允许用户输入值(以防它不在列表中)或从下拉列表中选择。
举个例子就好了!
谢谢,
提姆
【问题讨论】:
标签: c# javascript vb.net devexpress
我正在使用 devexpress ASPxComboBox,但是我想知道如何允许用户输入值(以防它不在列表中)或从下拉列表中选择。
举个例子就好了!
谢谢,
提姆
【问题讨论】:
标签: c# javascript vb.net devexpress
我编写了一个代码,如果按下 Enter 键,您可以将新项目添加到 ComboBox 的 Items 集合中。
<script type="text/javascript">
function findItemByText(editor, newText) {
for(var i = 0; i< editor.GetItemCount(); i++)
if(editor.GetItem(i).text == newText)
return true;
return false;
}
function tryAddNewItem(editor, newText) {
if(!findItemByText(editor, newText))
editor.AddItem(newText);
}
</script>
...
<dx:ASPxComboBox ID="ASPxComboBox1" runat="server" DropDownStyle="DropDown" ValueType="System.String"
Width="286px">
<Items>
<dx:ListEditItem Text="Item 0" Value="0" />
<dx:ListEditItem Text="Item 1" Value="1" />
</Items>
<ClientSideEvents KeyPress="function(s,e) {
if(e.htmlEvent.keyCode == 13)
tryAddNewItem(s, s.GetText());
}"/>
【讨论】:
DropDownStyle="DropDown" 而不是DropDownStyle="DropDownList",它允许输入新值。