<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jQueryAutocomplete.aspx.cs" Inherits="VipWinValidation.jQueryAutocomplete" %>编辑管理员
////// $codebehindclassname$ 的摘要说明 /// /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class LoadCountry : IHttpHandler { ////// /// /// 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"); // Listli = Country(strOperation); JavaScriptSerializer JS = new JavaScriptSerializer(); string sf = JS.Serialize(li); context.Response.Write(sf); } /// /// /// /// ///private List Country(string input) { //Get the countries list from database, for this example I am creating sample output //return GetCountriesfromDB(input); List li = new List (); 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; } /// /// /// ///private List GetCountries() { List CountryInformation = new List (); 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("涂聚文"); CountryInformation.Add("涂年生"); CountryInformation.Add("江西省"); CountryInformation.Add("江苏省"); CountryInformation.Add("浙江省"); return CountryInformation; } /// /// /// public bool IsReusable { get { return false; } } }
.net 4.0
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jQueryAutocomplete.aspx.cs" Inherits="DuCms.Web.jQueryAutocomplete" %>编辑管理员
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{ ////// /// public partial class jQueryAutocomplete : System.Web.UI.Page { ////// /// /// /// protected void Page_Load(object sender, EventArgs e) { } [WebMethod] public static ListLoadCountry(string input) { List li = new List (); //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; } /// /// /// ///public static List GetCountries() { List CountryInformation = new List (); 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("涂聚文"); CountryInformation.Add("涂年生"); CountryInformation.Add("江西省"); CountryInformation.Add("江苏省"); CountryInformation.Add("浙江省"); return CountryInformation; } }}