微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AutoCompleteExtender 自动补全控件

1.前台代码:  

js:

 <style type="text/css">
 
  .backgroudcolor
  {
   background-color:#D6FAF9;
  }
  .onmouservoer
  {
    background-color:#E9EDAF;
  }
  </style>
  

 

<div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
   
   
        <asp:TextBox ID="TextBox1" runat="server" AutopostBack="True"
            ontextchanged="TextBox1_TextChanged"></asp:TextBox>
        <cc1:autocompleteextender ID="autocompleteextender1" runat="server" TargetControlID="TextBox1"
         ServicePath="testwebservers.asmx" ServiceMethod="GetHotSearchBywords" MinimumPrefixLength="1" CompletionInterval="500"
          EnableCaching="true" CompletionSetCount="10"  CompletionListItemCssClass="backgroudcolor"  CompletionListHighlightedItemCssClass="onmouservoer">
        </cc1:autocompleteextender>
        </div>

2.后台代码:

webserver:

  [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolBoxItem(false)]
    // To allow this Web Service to be called from script,using ASP.NET AJAX,uncomment the following line.
    [System.Web.Script.Services.ScriptService]
    public class testwebservers : System.Web.Services.WebService
    {

        [WebMethod]

        public string[] GetHotSearchBywords(string prefixText,int count)
        {
            return BookManager.GetBookKeywords(prefixText,count);
        }

    }

 

bll 省略...

dal:

 public static string[] GetBookKeywords(string keyword,int displaycount)
      {
          IList<Book> book = new List<Book>();
          List<string> result = new List<string>(displaycount);

          string sql = "select top 10 * from Book where title like '%" + keyword + "%' order by id";

          book =getALLBookBysql(sql);

          foreach (Book item in book)
          {
              result.Add(item.Title);

          }          return result.ToArray();      }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐