Thursday, May 2, 2013

Ajax AutoCompleteExtender control sample in ASP.NET

It this Auto Complete Extender sample, when you enter a cursor in the TextBox the code behind list of values will be displayed in text box as a dropdown. For this sample you need to add Ajax Controll Toolkit in your application.
Design Code:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>  
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
<cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCountries()" MinimumPrefixLength="1" CompletionSetCount="12" CompletionInterval="500" EnableCaching="true">  
</cc1:AutoCompleteExtender>  

C# Code:
[WebMethod]  
[System.Web.Script.Services.ScriptMethod()]  
public static List<string> GetCountries()  
{  
    List<string> CountryNames = new List<string>();  
    CountryNames.Add("apple");  
    CountryNames.Add("orange");  
    CountryNames.Add("mango");  
    CountryNames.Add("banana");  
    return CountryNames;  
}  

No comments:

Post a Comment