你一定錯過了jQuery的自動完成選項,不正是你想要的。這將匹配馬克·亞當斯,當你鍵入A,d等
編輯
而對於ajaxtoolkit AutoCompleteExtender,我怕你沒有得到任何選項等同於jQuery的matchContains的。但你可以用服務方法輕鬆完成。其設置爲...
ServiceMethod="GetNameList"
其中GetNameList包含如何匹配數據的整個邏輯。例如。
public partial class _Default : System.Web.UI.Page {
[WebMethod]
public static string[] GetNameList(string prefixText, int count) {
string sql = String.Format("select name from customers where name like @given_name");
List<string> nameList = new List<string>();
using (SqlConnection connection = new SqlConnection("Integrated Security=SSPI;Initial Catalog=Northwind;Data Source=."))
using (SqlCommand command = new SqlCommand(sql, connection)) {
connection.Open();
command.Parameters.AddWithValue("@given_name", "%"+prefixText"%");
using (SqlDataReader reader = command.ExecuteReader()) {
while (reader.Read()) {
nameList.Add(reader.GetString(0));
}
}
}
return nameList.ToArray();
}
}
下面是代碼行,它進行匹配。
command.Parameters.AddWithValue("@given_name", "%"+prefixText"%");
檢查Ajax ToolKit的編輯。 – simplyharsh 2009-07-17 06:50:42