2011-05-30 209 views

回答

0
<script type="text/javascript"> 
    function autoComplete1_OnClientShown(sender, eventArgs) { 
     var valueToSelect = $("#<%= TextBox1.ClientID %>").val(); 

     if (valueToSelect.length > 0) { 
      var itemToSelect = $("li[_value^='" + valueToSelect + "']", ".CompletionList").get(0); 
      Sys.Debug.traceDump(itemToSelect); 
      if (itemToSelect) 
       $find("AutoCompleteEx")._setText(itemToSelect); 
     } 
    } 
</script> 

<asp:Label runat="server" AssociatedControlID="TextBox1" Text="Select the first value that starts with: " /> 
    <asp:TextBox runat="server" ID="TextBox1" />&nbsp; 
    <br /> 
    <asp:Label ID="Label1" runat="server" AssociatedControlID="TextBox2" Text="Choose value: " /> 
    <asp:TextBox runat="server" ID="TextBox2" /> 
    <ajax:AutoCompleteExtender runat="server" 
      BehaviorID="AutoCompleteEx" 
      ID="autoComplete1" 
      TargetControlID="TextBox2" 
      ServicePath="Default.aspx" 
      ServiceMethod="GetCompletionList" 
      MinimumPrefixLength="2" 
      DelimiterCharacters=";, :" 
      CompletionListCssClass="CompletionList" 
      OnClientShown="autoComplete1_OnClientShown" 
      ShowOnlyCurrentWordInCompletionListItem="false" > 
    </ajax:AutoCompleteExtender>