locked
dropdownlist filter not working if textandnumber RRS feed

  • Question

  • User-807418713 posted

    Dropdowlist not showing or focus not working

    07-13-2018 10:40 AM|LINK|157.51.143.48

    Hello

    This is my script

    <script type="text/javascript">
            $(function () {
                $(".chzn-select").chosen();
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
                function EndRequestHandler(sender, args) {
                    //Binding Code Again
                    $(".chzn-select").chosen();
                }
            });
        </script>
      <asp:DropDownList ID="D1" TabIndex="59" runat="server" class="chzn-select">
                    <asp:ListItem Text="Select Item Name"></asp:ListItem>
                    <asp:ListItem Text="United States" Value="United States" />
                    <asp:ListItem Text="India" Value="India" />
                    <asp:ListItem Text="France" Value="France" /> 
                   <asp:ListItem Text="Russia" Value="Russia" />		                   
    <asp:ListItem Text="Hello789" Value="Hello789" /> <asp:ListItem Text="1234" Value="1234" /> </asp:DropDownList>

    Its not filtering if my data is with text and number

    why.. for example Hello789

    if i enter 78 its not showing Hello789 why

    If complete text or number then its filtering else its not why..?

    Monday, July 23, 2018 2:33 PM

Answers

  • User-1171043462 posted

    Change as follows

    <script type="text/javascript">
            $(function () {
                $(".chzn-select").chosen({
                    search_contains: true                
                 });
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
                function EndRequestHandler(sender, args) {
                    //Binding Code Again
                    $(".chzn-select").chosen({
                    search_contains: true                
                 });
                }
            });
        </script>

    Ref: https://stackoverflow.com/questions/9274362/changing-search-behavior-in-jquery-plugin-chosen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 23, 2018 2:39 PM
  • User-1171043462 posted

    Working 100%

     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.css" />
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.jquery.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $(".chzn-select").chosen({
                    search_contains: true
                });
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
                function EndRequestHandler(sender, args) {
                    //Binding Code Again
                    $(".chzn-select").chosen({
                        search_contains: true
                    });
                }
            });
        </script>
        <asp:ScriptManager runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="D1" TabIndex="59" runat="server" class="chzn-select">
                    <asp:ListItem Text="Select Item Name"></asp:ListItem>
                    <asp:ListItem Text="United States" Value="United States" />
                    <asp:ListItem Text="India" Value="India" />
                    <asp:ListItem Text="France" Value="France" />
                    <asp:ListItem Text="Russia" Value="Russia" />
                </asp:DropDownList>
                <asp:Button Text="Add" ID="btnAdd" runat="server" OnClick="Add_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>
     protected void Add_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript((sender as Control), this.GetType(), "a", " $('.chzn-select').chosen({ search_contains: true });$('.chzn-select').trigger('chosen:open');", true);
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 23, 2018 2:49 PM

All replies

  • User-1171043462 posted

    Change as follows

    <script type="text/javascript">
            $(function () {
                $(".chzn-select").chosen({
                    search_contains: true                
                 });
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
                function EndRequestHandler(sender, args) {
                    //Binding Code Again
                    $(".chzn-select").chosen({
                    search_contains: true                
                 });
                }
            });
        </script>

    Ref: https://stackoverflow.com/questions/9274362/changing-search-behavior-in-jquery-plugin-chosen

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 23, 2018 2:39 PM
  • User-807418713 posted

    Change as follows

    <script type="text/javascript">
            $(function () {
                $(".chzn-select").chosen({
                    search_contains: true                
                 });
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
                function EndRequestHandler(sender, args) {
                    //Binding Code Again
                    $(".chzn-select").chosen({
                    search_contains: true                
                 });
                }
            });
        </script>

    Ref: https://stackoverflow.com/questions/9274362/changing-search-behavior-in-jquery-plugin-chosen

    I tried this its not working.. why 

    Monday, July 23, 2018 2:45 PM
  • User-1171043462 posted

    Working 100%

     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.css" />
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.jquery.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $(".chzn-select").chosen({
                    search_contains: true
                });
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
                function EndRequestHandler(sender, args) {
                    //Binding Code Again
                    $(".chzn-select").chosen({
                        search_contains: true
                    });
                }
            });
        </script>
        <asp:ScriptManager runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="D1" TabIndex="59" runat="server" class="chzn-select">
                    <asp:ListItem Text="Select Item Name"></asp:ListItem>
                    <asp:ListItem Text="United States" Value="United States" />
                    <asp:ListItem Text="India" Value="India" />
                    <asp:ListItem Text="France" Value="France" />
                    <asp:ListItem Text="Russia" Value="Russia" />
                </asp:DropDownList>
                <asp:Button Text="Add" ID="btnAdd" runat="server" OnClick="Add_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>
     protected void Add_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript((sender as Control), this.GetType(), "a", " $('.chzn-select').chosen({ search_contains: true });$('.chzn-select').trigger('chosen:open');", true);
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 23, 2018 2:49 PM
  • User-1171043462 posted

    You also need to apply in ScriptManager code

    protected void Add_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterStartupScript((sender as Control), this.GetType(), "a", " $('.chzn-select').chosen({ search_contains: true });$('.chzn-select').trigger('chosen:open');", true);
        }

    Monday, July 23, 2018 2:50 PM