AutoCompleteExtender

这是一个webservices,在aspx中调用就行了!
using System;
using System.IO;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;

/// <summary>
/// Summary description for AutoCompleteService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoCompleteService : System.Web.Services.WebService
{
public AutoCompleteService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}

private static string[] autoCompleteWordList = null;

[WebMethod]
//******光之翼 QQ272912705     www.hi.baidu.com/jcomet*******
public String[] GetWordList(string prefixText, int count)
{
if (autoCompleteWordList == null)
{
string[] temp = File.ReadAllLines(Server.MapPath("~/App_Data/words.txt"));
Array.Sort(temp, new CaseInsensitiveComparer());
autoCompleteWordList = temp;
}

int index = Array.BinarySearch(autoCompleteWordList, prefixText,
new CaseInsensitiveComparer());

if (index < 0)
{
index = ~index;
}

int matchingCount;
for (matchingCount = 0;
matchingCount < count && index + matchingCount < autoCompleteWordList.Length;
matchingCount++)
{
if (!autoCompleteWordList[index + matchingCount].StartsWith(prefixText,
StringComparison.CurrentCultureIgnoreCase))
{
break;
}
}

String[] returnValue = new string[matchingCount];

if (matchingCount > 0)
{
Array.Copy(autoCompleteWordList, index, returnValue, 0, matchingCount);
}

return returnValue;
}
}

转载于:https://www.cnblogs.com/jcomet/archive/2008/07/14/1242807.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值