在文本框中搜索cs用于自动填充

时间:2012-08-12 19:19:10

标签: jquery asp.net handler populate

<%@ 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文件中存在一些问题......

0 个答案:

没有答案