Hello in the following link, an article of yours titled auto complete with image, i have a doubt
http://www.aspsnippets.com/Articles/Configuring-jQuery-AutoComplete-Plugin-to-display-Images-in-ASP.Net.aspx
I am developing a movie database website and in that i included this auto complete with image feature for suggesting film names with the image of the film,film title and year of the film when the user types the first few words of a film.There is a button "search" next to the auto complete text box and if the user clicks that button it will take it to another page with the film title as query string and in that page i have written code to fetch details from database based on the film title query string. My problem is i want to fetch the details of the film in the page load event with the film_id value also i don't want to show the film_id value in the auto complete text box. How can i achieve this, please help me.
CODE FOR WEB HANDLER
<%@ WebHandler Language="C#" Class="Search_CS" %>
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 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", sdr["Title"], sdr["Year"]));
}
}
conn.Close();
context.Response.Write(sb.ToString());
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
CODE FOR MOVIE DETAILS PAGE
public partial class Movie_Details : System.Web.UI.Page
{
string title,ttl;
protected void Page_Load(object sender, EventArgs e)
{
//Rating Code Starts
if (!IsPostBack)
{
BindRatingControl();
}
//Rating Code Ends
title=Request.QueryString["title"];
SqlConnection con = ConnectionManager.getmoviedb();
string query = "select * from movie_details where title='"+title.ToString()+"'";
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
string url = dr["Poster_Path"].ToString();
Film_Poster.ImageUrl = url;
lbl_Film_Name.Text = dr["Title"].ToString();
lbl_Year.Text = dr["Year"].ToString();
lbl_Description.Text = dr["Description"].ToString();
lbl_Actor.Text = dr["Actor"].ToString();
lbl_Actress.Text = dr["Actress"].ToString();
lbl_Director.Text = dr["Director"].ToString();
lbl_Writer.Text = dr["Writer"].ToString();
lbl_Producer.Text = dr["Producer"].ToString();
lbl_Cinematography.Text = dr["cinematography"].ToString();
lbl_Music.Text = dr["Music"].ToString();
lbl_Lyrics.Text = dr["Lyrics"].ToString();
lbl_Choreographer.Text = dr["Choreography"].ToString();
lbl_Stunts.Text = dr["Stunts"].ToString();
lbl_Editor.Text = dr["Editor"].ToString();
lbl_Review.Text = dr["Review"].ToString();
int rating = Convert.ToInt32(dr["Rating"]);
}
}
else
{
con.Close();
Response.Redirect("Filter_Movie.aspx?title="+title+"");
}
}
protected void RatingControlChanged(object sender, AjaxControlToolkit.RatingEventArgs e)
{
Response.Redirect("~/coming_soon.aspx");
//con.Open();
//SqlCommand cmd = new SqlCommand("insert into RatingDetails(Rate)values(@Rating)",con);
//cmd.Parameters.AddWithValue("@Rating", ratingControl.CurrentRating);
//cmd.ExecuteNonQuery();
//con.Close();
//BindRatingControl();
}
protected void BindRatingControl()
{
//int total = 0;
//DataTable dt = new DataTable();
//con.Open();
//SqlCommand cmd = new SqlCommand("Select Rate from RatingDetails", con);
//SqlDataAdapter da = new SqlDataAdapter(cmd);
//da.Fill(dt);
//if (dt.Rows.Count > 0)
//{
// for (int i = 0; i < dt.Rows.Count; i++)
// {
// total += Convert.ToInt32(dt.Rows[i][0].ToString());
// }
// int average = total / (dt.Rows.Count);
// ratingControl.CurrentRating = average;
// lbltxt.Text = dt.Rows.Count + "user(s) have rated this article";
//}
}
}
JQUERY CODE
<script type="text/javascript">
$(document).ready(function() {
$("#<%=txtSearch.ClientID%>").autocomplete("Search_CS.ashx", {
width: 250,
formatItem: function(data, i, n, value) {
return "<img style = 'width:70px;height:70px' src='Posters/"+value.split("-")[1] + "'/> " + value.split("-")[0];
},
formatResult: function(data, value) {
return value.split("-")[0];
}
});
});
</script>
To be simple i want the film_id value of the film title that the user selects as the query string which is used as search condition in the redirected page because there can be two film titles with the same name