Hi

Autocomplete

In Clien Side:
<asp:UpdatePanel ID="updart" runat="server">
<ContentTemplate>
     <asp:TextBox ID="txtNewCategoryType" runat="server" AutoPostBack="true"></asp:TextBox>
    <Ajax:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" DelimiterCharacters=","
  TargetControlID="txtNewCategoryType" ServicePath="~/WebServices/WebService11.asmx"
 ServiceMethod="GetAllNames" CompletionSetCount="20" MinimumPrefixLength="1" EnableCaching="false"                                     CompletionListHighlightedItemCssClass="AutoCompleteExtender_HighlightedItem"
CompletionListCssClass="AutoCompleteExtender_CompletionList1"  CompletionInterval="0">
   </Ajax:AutoCompleteExtender>
    </ContentTemplate>
      </asp:UpdatePanel>

Webservice:
    [WebMethod]
    public string[] GetAllNames(string prefixText, int count)
    {
        ArrayList filteredList = new ArrayList();
        string[] names = { "ss", "dfghy", "gyu", "guj", "ghj", "hgjk" };
        foreach (string name in names)
        {
            if (name.ToLower().StartsWith(prefixText.ToLower()))
                filteredList.Add(name);
        }
        return (string[])filteredList.ToArray(typeof(string));
    }


Another one:

<asp:ScriptManager ID="ScriptManager1" runat="server" 
EnablePageMethods = "true">
</asp:ScriptManager>

Enter a Product Name
<asp:TextBox ID="txtProductList" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="GetProductList" 
    MinimumPrefixLength="1"
    CompletionInterval="0" EnableCaching="false" CompletionSetCount="10" 
    TargetControlID="txtProductList"
    ID="autoCompleteExtender1" runat="server" FirstRowSelected = "false">
</cc1:AutoCompleteExtender>


public static string[] GetProductList(string prefixText, int count)
    {
        // Get the Products From Data Source. Change this method to use Database
        List<string> productList = GetProducts();

        // Find All Matching Products
        var list = from p in productList
                   where p.Contains(prefixText)
                   select p;

        //Convert to Array as We need to return Array
        string[] prefixTextArray = list.ToArray<string>();

        //Return Selected Products
        return prefixTextArray;
    }  
Previous
Next Post »