Posted by : Anwar Hossain
Category : How to use ajax toolkit in asp.net C#

How to use Ajax AutoCompleteExtender control in asp.net using c#

Dear viewers I will show how to use an AutoCompleteExtender control to a TextBox in order to display auto-complete suggestions item. The AutoCompleteExtender works with a standard ASP.NET TextBox control .At first I have taken a TextBox and an AutoCompleteExtender. Then Codebehind page I have created Employee list to supply data to TextBox and an AutoCompleteExtender but real-time list will be created by collecting data from database. I have shown this example without using Webservice.

Ajax AutoCompleteExtender control

HTML

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>AutoComplete Extender</title>
</head>
<body>
  <form runat="server">
  <div>
  <b style = "color:Red;">Enter Customer Name</b>
  <asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
  <asp:AutoCompleteExtender ID="txtContactsSearch_AutoCompleteExtender" MinimumPrefixLength="1"
  ServiceMethod="SearchCustomers" CompletionInterval="100" EnableCaching="false"
  CompletionSetCount="10" TargetControlID="txtContactsSearch" runat="server" FirstRowSelected="false">
  </asp:AutoCompleteExtender>
  <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
  </asp:ScriptManager>
  </div>
  </form>
</body>
</html>

CODE BEHIND

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
public partial class AutoCompleteExtender : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
 
  }
  private static List<Customer > GetStudent()
  {
  List<Customer > Customers = new List<Customer >()
   {
    new Customer  {Name = "Roman"},
    new Customer  {Name = "Iqbal"},
    new Customer  { Name = "Amin"},
    new Customer  {  Name = "Asad"},
    new Customer  {  Name = "Abul"},
    new Customer  {  Name = "Abaden"},
    new Customer  { Name = "M Ali"},
    new Customer  {  Name = "Ashikur Rhaman"},
    new Customer  {  Name = "Abdul"},
    new Customer  {  Name = "Asif"},
    new Customer  {  Name = "Aminur"},
    new Customer  {  Name = "Arifur Rahman"},
    new Customer  {  Name = "Asgor"},
    new Customer  {  Name = "Abul Momen"
 
  };
  return Customers;
  }
  public class Customer
  {
   
    public string Name { get; set; }
     
  }
  [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
  public static List<string> SearchCustomers(string prefixText, int count)
  {
  List<Customer > CustomeList = GetStudent();
  var query = from m in CustomeList
 
  select m.Name.ToString();
  try
  {
  return (from customer in query
  where customer.ToLower().StartsWith(prefixText.ToLower())
  select customer).Take (count).ToList<string>();
 
  }
  catch (Exception ex )
  {
 
  throw new Exception("Problem Loading in finding customer" + ex.Message);
  } 
 
  }
 
}

Out Put

ASP.Net-AJAX-_Control-Toolkit-AutoCompleteExtender-Control



Realted Article Headline

How to use TextBoxWatermarkExtender in asp.net using c#
How to use Ajax AutoCompleteExtender control in asp.net using c#
How to use Ajax Collapsible panel control in asp.net c#
How to use ASP.Net AJAX Control Toolkit ModalPopupExtender Control in asp.net c#
how to add an Ajax Control Toolkit Accordion to a page
How to use html editor Ajax control toolkit example in c#
How to use Ajax ConfirmButtonExtender in asp.net using c#
how to use ajax calendar extender in asp net c#
How to use ajax toolkit FilteredTextBox Control in c#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection