Click here to Skip to main content
15,888,232 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using JQuery autocomplete to search from textbox.
I am able to search the data but i need to get the ID of related search Value.
I am getting the last value of search Item....
Suppose search the item with a letter......example....
Ashraf
Amar
Ankit
i got the Id of last Item value ie.Ankit ....but i need to access the Id of related Name.

Please can anybody help me?

C#
public class SearchDoctor : IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        string prefixText = context.Request.QueryString["q"];
        using (SqlConnection conn = new SqlConnection())
        {
            conn.ConnectionString = ConfigurationManager
                    .ConnectionStrings["Connect"].ConnectionString;
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "select MiddleName,Doctor_ID from DoctorMaster where " +
                "MiddleName like @SearchText + '%'";
                cmd.Parameters.AddWithValue("@SearchText", prefixText);
                cmd.Connection = conn;
                StringBuilder sb = new StringBuilder();
                conn.Open();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        sb.Append(sdr["MiddleName"])
                            .Append(Environment.NewLine);
                        string s = sdr["Doctor_ID"].ToString();
                        HttpContext.Current.Session["doctorid"] = s.ToString();
                    }

                }
                conn.Close();
                context.Response.Write(sb.ToString());

            }
        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}
Posted
Comments
[no name] 13-Oct-14 4:05am    
Post your javascript code, not the server side.:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900