搜索功能
自动完成输入提示:
VS2010工具栏添加新项AjaxControlToolkit.dll
前台:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
搜索 :
<asp:TextBox ID="txtSearch" runat="server" Height="25px" Width="359px"></asp:TextBox>
<asp:AutoCompleteExtender
ID="AutoCompleteExtender1"
runat="server"
TargetControlID="txtSearch"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
MinimumPrefixLength="2"
CompletionSetCount="10"
></asp:AutoCompleteExtender>
<!--MinimumPrefixLength:出现提示时的文字最小长度,CompletionSetCount:文本提示的个数-->
WebServices 服务:
==================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
///AutoComplete 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class AutoComplete : System.Web.Services.WebService {
public AutoComplete () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public string[] GetCompletionList(string prefixText, int count)
{
List<string> strList = new List<string>();
count = count == 0 ? 10 : count;
Random r = new Random();
for (int i = 0; i < count; i++)
{
string newStr= ((char)(r.Next(65, 90))+(char)(r.Next(97, 122))+(char)(r.Next(97,122))).ToString();
strList.Add(prefixText + newStr);
}
return strList.ToArray();
}
}