zoukankan      html  css  js  c++  java
  • AJAX中利用AutoCompleteExtender实现类似于谷歌的智能提示(利用记事本)

    1、打开VS,添加TextFile1.txt、WebForm1.aspx、WebService1.asmx;

    2、在TextFile1.txt添加如下图所示数据:

    3、在WebService1.asmx中添加GetCompleteList方法,代码如下:

    GetCompleteList方法
     [WebMethod]
            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[index + matchingCount].StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase))
                        {
                            break;
                        }
                    }
                    String[] returnValue = new string[matchingCount];
                    if (matchingCount > 0)
                    {
                        Array.Copy(autoCompleteWordList, index, returnValue, 0, matchingCount);
                    }
                    return returnValue;
                }
                else
                {
                    autoCompleteWordList = null;
                    return null;
                }
            }

    4、在WebForm1.aspx窗体中添加源码:

    WebForm1.aspx源码
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <p class="style1">省份智能提示:</p>
            <asp:TextBox ID="TextBox1" runat="server" Height="18px" Width="184px"></asp:TextBox>
            <br />
            <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServiceMethod="GetCompleteList"
             ServicePath="~/WebService1.asmx" Enabled="true" MinimumPrefixLength="1" CompletionSetCount="8" TargetControlID="TextBox1">
            </asp:AutoCompleteExtender>
        </div>
        </form>
    </body>

    5、在浏览器中查看如图:

  • 相关阅读:
    iOS-修改导航栏文字字体和颜色
    iOS-cocoapods使用方法
    iOS-创建UIScrollerView(封装UIScrollerView)
    iOS-根据两个经纬度计算相距距离
    iOS-JS调用OC代码
    iOS-tableView刷新指定行,组
    雷赛dmc2410控制卡,驱动器 光栅 加电机
    做自己的类库dll文件
    Sender
    BackGroundWorker控件的使用注意
  • 原文地址:https://www.cnblogs.com/wynet/p/2777734.html
Copyright © 2011-2022 走看看