ASPxCombobox, allow user input and shutdown

I am using devexpress ASPxComboBox, however I wanted to know how I can let the user enter values ​​(in case they are not in the list) or select from the drop-down list.

An example will be great!

Thank,

Tim

+3
source share
1 answer

I wrote code that allows you to add a new item to the ComboBox Items collection if the Enter key is pressed.

   <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());
            }"/>

+1
source

Source: https://habr.com/ru/post/1753873/


All Articles