您的位置:首页 > 编程语言 > Go语言

使用ajaxToolkit组件实现类型google,百度下拉框匹配功能

2009-12-05 14:28 856 查看
效果图如下,数据库连接的是pubs的authors表

代码

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class AutoCompleteService : System.Web.Services.WebService
{

[WebMethod]
[ScriptMethod]
public string[] GetSearchTerms(string prefixText, int count)
{
SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=pubs;Persist Security Info=True;User ID=sa;Password=123;");
SqlCommand cmd = new SqlCommand(
"SELECT DISTINCT au_lname FROM authors WHERE au_lname like @term", cn);
cmd.Parameters.AddWithValue("nrows", count);
cmd.Parameters.AddWithValue("term", prefixText + "%");
List<string> suggestions = new List<string>();
cn.Open();
using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
while (dr.Read())
suggestions.Add(dr[0].ToString());
}
return suggestions.ToArray();
}

完整源码和AjaxControlToolkit.dll请从群中下载:74085440
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: