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:
  1. <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
  2. <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  3. <cc1:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCountries()" MinimumPrefixLength="1" CompletionSetCount="12" CompletionInterval="500" EnableCaching="true">
  4. </cc1:AutoCompleteExtender>

C# Code:
  1. [WebMethod]
  2. [System.Web.Script.Services.ScriptMethod()]
  3. public static List<string> GetCountries()
  4. {
  5. List<string> CountryNames = new List<string>();
  6. CountryNames.Add("apple");
  7. CountryNames.Add("orange");
  8. CountryNames.Add("mango");
  9. CountryNames.Add("banana");
  10. return CountryNames;
  11. }

No comments:

Post a Comment