Click here to Skip to main content
15,741,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to add a textbox for searching items in dropdownlist and checkboxlist for multiple selection inside dropdownlist


my code here but did not perform complete task


XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Autocomplete - Combobox</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <style>
  .custom-combobox {
    position: relative;
    display: inline-block;
  }
  .custom-combobox-toggle {
    position: absolute;
    top: 0;
    bottom: 0;
    margin-left: -1px;
    padding: 0;
    /* support: IE7 */
    *height: 1.7em;
    *top: 0.1em;
  }
  .custom-combobox-input {
    margin: 0;
    padding: 0.3em;
  }
  </style>
  <script>
  (function( $ ) {
    $.widget( "custom.combobox", {
      _create: function() {
        this.wrapper = $( "<span>" )
          .addClass( "custom-combobox" )
          .insertAfter( this.element );

        this.element.hide();
        this._createAutocomplete();
        this._createShowAllButton();
      },

      _createAutocomplete: function() {
        var selected = this.element.children( ":selected" ),
          value = selected.val() ? selected.text() : "";

        this.input = $( "<input>" )
          .appendTo( this.wrapper )
          .val( value )
          .attr( "title", "" )
          .addClass( "custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left" )
          .autocomplete({
            delay: 0,
            minLength: 0,
            source: $.proxy( this, "_source" )
          })
          .tooltip({
            tooltipClass: "ui-state-highlight"
          });

        this._on( this.input, {
          autocompleteselect: function( event, ui ) {
            ui.item.option.selected = true;
            this._trigger( "select", event, {
              item: ui.item.option
            });
          },

          autocompletechange: "_removeIfInvalid"
        });
      },

      _createShowAllButton: function() {
        var input = this.input,
          wasOpen = false;

        $( "<a>" )
          .attr( "tabIndex", -1 )
          .attr( "title", "Show All Items" )
          .tooltip()
          .appendTo( this.wrapper )
          .button({
            icons: {
              primary: "ui-icon-triangle-1-s"
            },
            text: false
          })
          .removeClass( "ui-corner-all" )
          .addClass( "custom-combobox-toggle ui-corner-right" )
          .mousedown(function() {
            wasOpen = input.autocomplete( "widget" ).is( ":visible" );
          })
          .click(function() {
            input.focus();

            // Close if already visible
            if ( wasOpen ) {
              return;
            }

            // Pass empty string as value to search for, displaying all results
            input.autocomplete( "search", "" );
          });
      },

      _source: function( request, response ) {
        var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
        response( this.element.children( "option" ).map(function() {
          var text = $( this ).text();
          if ( this.value && ( !request.term || matcher.test(text) ) )
            return {
              label: text,
              value: text,
              option: this
            };
        }) );
      },

      _removeIfInvalid: function( event, ui ) {

        // Selected an item, nothing to do
        if ( ui.item ) {
          return;
        }

        // Search for a match (case-insensitive)
        var value = this.input.val(),
          valueLowerCase = value.toLowerCase(),
          valid = false;
        this.element.children( "option" ).each(function() {
          if ( $( this ).text().toLowerCase() === valueLowerCase ) {
            this.selected = valid = true;
            return false;
          }
        });

        // Found a match, nothing to do
        if ( valid ) {
          return;
        }

        // Remove invalid value
        this.input
          .val( "" )
          .attr( "title", value + " didn't match any item" )
          .tooltip( "open" );
        this.element.val( "" );
        this._delay(function() {
          this.input.tooltip( "close" ).attr( "title", "" );
        }, 2500 );
        this.input.data( "ui-autocomplete" ).term = "";
      },

      _destroy: function() {
        this.wrapper.remove();
        this.element.show();
      }
    });
  })( jQuery );

  $(function() {
    $( "#combobox" ).combobox();
    $( "#toggle" ).click(function() {
      $( "#combobox" ).toggle();
    });
  });
  </script>
</head>
<body>
 <form id="form1" runat="server">
<div class="ui-widget">
  <label>Your preferred programming language: </label>
  <asp:DropDownList ID="combobox" runat="server" AutoPostBack="true"
        onselectedindexchanged="combobox_SelectedIndexChanged">

    <asp:ListItem Text="A" Value="A"></asp:ListItem>
        <asp:ListItem Text="ActionScript" Value="AB"></asp:ListItem>
        <asp:ListItem Text="AppleScript" Value="AC"></asp:ListItem>
        <asp:ListItem Text="AD" Value="AD"></asp:ListItem>
        <asp:ListItem Text="AE" Value="AE"></asp:ListItem>
        <asp:ListItem Text="B" Value="B"></asp:ListItem>
        <asp:ListItem Text="C" Value="C"></asp:ListItem>
        <asp:ListItem Text="D" Value="D"></asp:ListItem>
        <asp:ListItem Text="E" Value="E"></asp:ListItem>
        <asp:ListItem Text="F" Value="F"></asp:ListItem>
        <asp:ListItem Text="G" Value="G"></asp:ListItem>
        <asp:ListItem Text="H" Value="H"></asp:ListItem>
        <asp:ListItem Text="I" Value="I"></asp:ListItem>
        <asp:ListItem Text="J" Value="J"></asp:ListItem>
        <asp:ListItem Text="K" Value="K"></asp:ListItem>
        <asp:ListItem Text="L" Value="L"></asp:ListItem>
        <asp:ListItem Text="M" Value="M"></asp:ListItem>
        <asp:ListItem Text="N" Value="N"></asp:ListItem>
        <asp:ListItem Text="O" Value="O"></asp:ListItem>
        <asp:ListItem Text="P" Value="P"></asp:ListItem>
        <asp:ListItem Text="Q" Value="Q"></asp:ListItem>
        <asp:ListItem Text="R" Value="R"></asp:ListItem>
        <asp:ListItem Text="S" Value="S"></asp:ListItem>
        <asp:ListItem Text="T" Value="T"></asp:ListItem>
        <asp:ListItem Text="U" Value="U"></asp:ListItem>
        <asp:ListItem Text="V" Value="V"></asp:ListItem>
        <asp:ListItem Text="W" Value="W"></asp:ListItem>
        <asp:ListItem Text="X" Value="X"></asp:ListItem>
        <asp:ListItem Text="Y" Value="Y"></asp:ListItem>
        <asp:ListItem Text="Z" Value="Z"></asp:ListItem>

    </asp:DropDownList>
</div>
<button id="toggle">Show underlying select</button>
 <asp:Label ID="Label1" runat="server"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 </form>
</body>
</html>
Posted
Updated 11-Oct-13 21:21pm
v3
Comments
Ashwani Gusain 12-Oct-13 3:16am    
what you want exactly?
Member 10192073 12-Oct-13 3:18am    
i want like this i want like this in my project
example third
http://www.xnodesystems.com/Demo/Default.aspx#id=10[^]
Member 10192073 12-Oct-13 3:19am    
see example 3 in this link i want like as example 3 in this link

1 solution

Try this CP link which adds search , multiselect capabilities for your dropdown .

MultiDropDown v2: A Multiple Selection Dropdown Control for ASP.NET[^]

Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900