简体   繁体   中英

Select2 to make dropdown menu searchable

I am using Select2 to make my dropdown menu searchable and it works as it should on its first pass. It only works on the first try, after the first it goes back to a standard dropdown menu. It is like it ignores it after I use the dropdown once....

Code :

<div id="div" runat="server" visible="true">
    <asp:DropDownList AutoPostBack="true" ID="drpdown" runat="server" CssClass="search form-control" EnableViewState="true" OnSelectedIndexChanged="drpdown_Change">
    </asp:DropDownList>
</div> 

<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>
<script type="text/javascript">
     $(document).ready(function () {
            $('.search').select2();
        });
</script>

Can anyone tell me why this is happening or if this is a common issue?

Not sure how your code look's like because jquery is not loaded in above code. And also not clear if div will be inside an update panel. For regular use you can check this sample: http://manojjoshig.blogspot.ro/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM