this is the code in aspx age
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="search.aspx.cs" Inherits="search1" %>
$(document).ready(function () {
$("#<%=txtSearch.ClientID%>").autocomplete("Search.ashx", {
width: 200,
formatItem: function (data, i, n, value) {
return "
" + value.split(",")[0];
},
formatResult: function (data, value) {
return value.split(",")[0];
}
});
});
and my .ashx (generics handler) code is
<%@ WebHandler Language="C#" Class="Search" %>
using System;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Configuration;
public class Search : IHttpHandler {
public void ProcessRequest (HttpContext context)
{
string searchText = context.Request.QueryString["q"];
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=apcamp;User ID=sa;Password=123");
con.Open();
SqlCommand cmd = new SqlCommand("select id,imagename,imagepath from imagespath where imagename Like @Search + '%'", con);
cmd.Parameters.AddWithValue("@Search",searchText);
StringBuilder sb = new StringBuilder();
using(SqlDataReader dr=cmd.ExecuteReader())
{
while(dr.Read())
{
sb.Append(string.Format("{0},{1}{2}",dr["imagename"],dr["imagepath"],Environment.NewLine));
}
}
con.Close();
context.Response.Write(sb.ToString());
}
public bool IsReusable
{
get
{
return false;
}
}
}
i cant get either autocomplete or search results
can any one help me out
Thanks and Regards
ashok kumarPosted Aug 26, 2013, 5:44 AM