zwy_net 发表于 2013-1-1 22:08:02

AJAX中利用AutoCompleteExtender实现类似于谷歌的智能提示(利用记事本)

<div id="cnblogs_post_body">1、打开VS,添加TextFile1.txt、WebForm1.aspx、WebService1.asmx;
2、在TextFile1.txt添加如下图所示数据:
http://pic002.cnblogs.com/images/2012/387560/2012111917171970.jpg
3、在WebService1.asmx中添加GetCompleteList方法,代码如下:
<div class="cnblogs_code" >http://images.cnblogs.com/OutliningIndicators/ContractedBlock.gifhttp://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gifGetCompleteList方法<div id="cnblogs_code_open_2ababa0e-c41f-47cf-bbc1-42f39162539a" class="cnblogs_code_hide">       public String[] GetCompleteList(string prefixText, int count)      {            if (autoCompleteWordList == null)            {                string[] temp = File.ReadAllLines(Server.MapPath("./TextFile1.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 matchingCount].StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase))                  {                        break;                  }                }                String[] returnValue = new string;                if (matchingCount > 0)                {                  Array.Copy(autoCompleteWordList, index, returnValue, 0, matchingCount);                }                return returnValue;            }            else            {                autoCompleteWordList = null;                return null;            }      }
页: [1]
查看完整版本: AJAX中利用AutoCompleteExtender实现类似于谷歌的智能提示(利用记事本)