Skip to content
Loading
How to create Autocomplete textbox in Content page Asp.net
 .cs Page
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Data.SqlClient;  
  6. using System.Linq;  
  7. using System.Web.Script.Services;  
  8. using System.Web.Services;  
  9. using System.Web.UI.WebControls;  
  10.   
  11. namespace WebApp1  
  12. {  
  13.     public partial class AutoCompleteTextBox : System.Web.UI.Page  
  14.     {  
  15.         protected void Page_Load(object sender, EventArgs e)  
  16.         {  
  17.   
  18.         }  
  19.   
  20.         [WebMethod]  
  21.         [ScriptMethod(ResponseFormat = ResponseFormat.Json)]  
  22.         public static List<string> GetAutoComplete(string pre)  
  23.         {  
  24.             DataTable dtData = new DataTable();  
  25.             string conString = ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString;  
  26.             SqlConnection sqlCon = new SqlConnection(conString);  
  27.             sqlCon.Open();  
  28.             SqlCommand sqlCmd = new SqlCommand("Select BankName From BankMaster Where BankName Like '" + pre + "%'", sqlCon); //  
  29.             SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);  
  30.             sqlDa.Fill(dtData);  
  31.             sqlCon.Close();  
  32.             return (from row in dtData.AsEnumerable() select row["BankName"].ToString()).ToList();  
  33.         }  
  34.     }  

  • Dipa Mehta
    https://www.aspdotnet-suresh.com/2015/05/jquery-autocomplete-textbox-example-in-master-using-webservice-in-aspnet.html?m=1 Find your solution here. Might be it works. Good luck.