2010-07-09 139 views

回答

1

我已经写了代码,它允许你如果按下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()); 
      }"/> 

+3

注意'DropDownStyle = “下拉”',而不是'DropDownStyle = “DropDownList的”',它允许一个新值键入。 – 2012-03-29 20:53:21

+0

谢谢你的回答! :) – danbord 2013-09-17 17:45:30

相关问题