Hi i am developing a movie database, in that i have autpcomplete with image feature for the users to search film titles. In that when the text box suggests the film titles with image if the user clicks the film title the title text is copied into the text box and if we click the search button then only it is redirecting to another page, my requierement is when the suggestion comes and if the user clicks a particular suggestion the page has to be redirected to another page and there i have written code to fetch details of the film from the database. I have used web service and the code is
<%@ 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 {
public void ProcessRequest (HttpContext context) {
string prefixText = context.Request.QueryString["q"];
using (SqlConnection conn = ConnectionManager.getmoviedb())
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select title,year,film_id from movie_details where title like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
StringBuilder sb = new StringBuilder();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
sb.Append(string.Format("{0} ({1})-{0}.jpg-{2}",sdr["Title"], sdr["Year"],Environment.NewLine,sdr["film_id"]));
}
}
conn.Close();
context.Response.Write(sb.ToString());
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
<script type="text/javascript">
$(document).ready(function() {
$("#<%=txtSearch.ClientID%>").autocomplete("Search_CS.ashx", {
width: 300,
formatItem: function(data, i, n, value) {
return "<li><a href='/movie_details.aspx?title=" + value.split("-")[0]"&year="+value.split("-")[1]+"</a>" + "<img style = 'width:80px;height:80px' src='Posters/" + value.split("-")[1] + "'/> " + value.split("-")[0] + "</li>";
},
formatResult: function(data, value) {
return value.split("-")[0];
}
});
});
</script>
please help me to correct the above code. to be simple my logic is same as that used in imdb