首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

AutoCompleteExtender自动提示功能,如何弄不成呢?帮忙哦

2012-09-10 
AutoCompleteExtender自动提示功能,怎么弄不成呢??帮忙哦`[System.Web.Script.Services.ScriptService][We

AutoCompleteExtender自动提示功能,怎么弄不成呢??帮忙哦`
[System.Web.Script.Services.ScriptService]
  [WebMethod]
  public string [] AutoCompleteMethod(string prefixText,int count) {
  return new BookShop.BLL.SearchKeywordsManger().GetHotSearchByKeyword(prefixText,count);
  }
   
}
下面是后台代码:
 public class SearchKeywordsService
  {
  #region 获得Keyword
  public string[] GetHotSearchByKeyword(string prefixText,int count)
  {
  string sql = "select top " + count.ToString() + " * from [SearchKeywords] where [Keyword] like '" + prefixText + "%'";
  List<SearchKeywords> list = getKeywords(CommandType.Text, sql, null);
  List<string> reasult = new List<string>();
  foreach (SearchKeywords item in list)
  {
  reasult.Add(item.Keyword);
  }
  return reasult.ToArray();
  }
  #endregion

  #region 普通查询方法
  private List<SearchKeywords> getKeywords(CommandType commandType,string commText,params SqlParameter [] paras )
  {
  List<SearchKeywords> list = new List<SearchKeywords>();
  using (SqlDataReader reader=DBHelper .ExecuteGetReader2 (commandType ,commText ,paras))
  {
  while (reader .Read() )
  {
  list.Add(new SearchKeywords
  {
  Id =(int) reader ["Id"],
  Keyword =reader ["Keyword"].ToString (),
  SearchCount =(int) reader["SearchCount"]
  });
  }
  }
  return list;
这是控件代码:
<div id="search">
  <asp:ScriptManager ID="ScriptManager1" runat="server">
  </asp:ScriptManager>
  <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" 
  CompletionSetCount="5" MinimumPrefixLength="2" 
  ServiceMethod="AutoCompleteMethod" 
  ServicePath="~/myWebService/AutoCompleteService.asmx" 
  TargetControlID="txtKeyWord">
  </asp:AutoCompleteExtender>
  <asp:TextBox ID="txtKeyWord" runat="server" CssClass="search_key"></asp:TextBox>&nbsp;<asp:Button
  ID="btnSearch" runat="server" Text="" CssClass="search_sub" 
  onclick="btnSearch_Click" />

[解决办法]
下一个ajaxtookit,自带有例子,需要用到webservices。

热点排行