<%@ WebHandler Language="C#" Class="Search_CS" %>
using System;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
public class Search_CS : IHttpHandler {
ClassData clsDt = new ClassData();
public void ProcessRequest (HttpContext context) {
string prefixText = context.Request.QueryString["prefixText"];
string kk = clsDt.getDataTable("select ContactName from Customers where " + "ContactName like @SearchText + '%'").Rows[0][0].ToString();
using (SqlCommand cmd = new SqlCommand())
{
switch (prefixText)
{
case "1":
//tb1
cmd.CommandText = kk;
break;
case "2":
//tb2
cmd.CommandText = kk;
break;
}
//cmd.CommandText = "select ContactName from Customers where " + "ContactName like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = clsDt.sqlCnn;
StringBuilder sb = new StringBuilder();
clsDt.sqlCnn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
sb.Append(sdr["ContactName"])
.Append(Environment.NewLine);
}
}
clsDt.sqlCnn.Close();
context.Response.Write(sb.ToString());
}
}
public bool IsReusable {
get {
return false;
}
}
}
我有一个文件ashx ..通过它我想在我的文本框中使用autocompleate插件jquery填充建议......
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/jquery.autocomplete.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#txtSearch").autocomplete('Search_CS.ashx?prefixText=1');
$("#TextBox1").autocomplete('Search_CS.ashx?prefixText=2');
});
</script>
以上是jquery客户端
ashx文件中存在一些问题......