JQuery: SP. NET Autocomplete Textbox Using jQuery, JSON and AJAX, jqueryautocomplete
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "jQueryAutocomplete. aspx. cs" Inherits = "VipWinValidation. jQueryAutocomplete" %> <! DOCTYPE html>
/// <Summary> /// $ codebehindclassname $ abstract description /// </summary> [WebService (Namespace =" http://tempuri.org/ ")] [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] public class LoadCountry: IHttpHandler {// <summary> //// </summary> /// <param name = "context"> </param> public void ProcessRequest (HttpContext context) {HttpRequest request = context. request; HttpResponse response = context. response; System. collections. specialized. nameValueCollection forms = context. request. form; string strOperation = forms. get ("term"); // List <string> li = Country (strOperation); JavaScriptSerializer JS = new JavaScriptSerializer (); string sf = JS. serialize (li); context. response. write (sf );} /// <summary> ///// </summary> /// <param name = "input"> </param> /// <returns> </returns> private List <string> Country (string input) {// Get the countries list from database, for this example I am creating sample output // return GetCountriesfromDB (input); List <string> li = new List <string> (); foreach (string s in GetCountries () {string st = s. toLower (); if (st. contains (input. toLower () {li. add (s) ;}// Linq // return GetCountries (). findAll (item => item. toLower (). contains (input. toLower (); return li ;} /// <summary> ///// </summary> /// <returns> </returns> private List <string> GetCountries () {List <string> CountryInformation = new List <string> (); CountryInformation. add ("India"); CountryInformation. add ("United States"); CountryInformation. add ("United Kingdom"); CountryInformation. add ("Canada"); CountryInformation. add ("South Korea"); CountryInformation. add ("France"); CountryInformation. add ("Mexico"); CountryInformation. add ("Russia"); CountryInformation. add ("Australia"); CountryInformation. add ("Turkey"); CountryInformation. add ("Kenya"); CountryInformation. add ("New Zealand"); CountryInformation. add ("tu juwen"); CountryInformation. add ("tu Nian Sheng"); CountryInformation. add ("Jiangxi Province"); CountryInformation. add ("Jiangsu Province"); CountryInformation. add ("Zhejiang Province"); return CountryInformation;} // <summary> /// </summary> public bool IsReusable {get {return false ;}}}
. Net 4.0
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "jQueryAutocomplete. aspx. cs" Inherits = "DuCms. Web. jQueryAutocomplete" %> <! DOCTYPE html>
Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; using System. web. services; namespace DuCms. web {// <summary> ///// </summary> public partial class jQueryAutocomplete: System. web. UI. page {// <summary> //// </summary> /// <param name = "sender"> </param> /// <param name = "e"> </param> protected void Page_Load (object sender, eventArgs e) {} [WebMethod] public static List <string> LoadCountry (string input) {List <string> li = new List <string> (); // Get the countries list from database, for this example I am creating sample output // return GetCountriesfromDB (input); li = GetCountries (). findAll (item => item. toLower (). contains (input. toLower (); return li ;} /// <summary> ///// </summary> /// <returns> </returns> public static List <string> GetCountries () {List <string> CountryInformation = new List <string> (); CountryInformation. add ("India"); CountryInformation. add ("United States"); CountryInformation. add ("United Kingdom"); CountryInformation. add ("Canada"); CountryInformation. add ("South Korea"); CountryInformation. add ("France"); CountryInformation. add ("Mexico"); CountryInformation. add ("Russia"); CountryInformation. add ("Australia"); CountryInformation. add ("Turkey"); CountryInformation. add ("Kenya"); CountryInformation. add ("New Zealand"); CountryInformation. add ("tu juwen"); CountryInformation. add ("tu Nian Sheng"); CountryInformation. add ("Jiangxi Province"); CountryInformation. add ("Jiangsu Province"); CountryInformation. add ("Zhejiang Province"); return CountryInformation ;}}}