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> <asp:Button
ID="btnSearch" runat="server" Text="" CssClass="search_sub"
onclick="btnSearch_Click" />
------解决方案--------------------
下一个ajaxtookit,自带有例子,需要用到webservices。