Click here to Skip to main content
15,891,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Could you please help me in highlighting the typed words in the auto complete text box. i am already populating the auto-complete words and i need to just highlight the typed words alone.i am new to Jquery auto-complete.

My code is:

JavaScript
<script type="text/javascript">
    $(document).ready(function () {
        SearchText();
    });
    function SearchText() {
        $(".autosuggest").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "Default.aspx/GetAutoCompleteData",
                    data: "{'username':'" + document.getElementById('txtSearch').value + "'}",
                    dataType: "json",
                    success: function (data) {
                        response(data.d);

                    },
                    error: function (result) {
                        alert("Error");
                    }
                });
            }
        });
    }
</script>


C#
 [WebMethod]
public static List<string> GetAutoCompleteData(string username)
{
    List<string> result = new List<string>();
    using (SqlConnection con = new SqlConnection("Data Source=192.168.10.120;Initial Catalog=StockImageBank2014Apr;User ID=sa;password=sib"))
    {
        using (SqlCommand cmd = new SqlCommand("select top (10) SubCategory from PhotographySubCategory where SubCategory LIKE '%'+@SearchText+'%'", con))
        {
            con.Open();
            cmd.Parameters.AddWithValue("@SearchText", username);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                result.Add(dr["SubCategory"].ToString());
            }
            return result;
        }
    }
}
Posted
Updated 27-Aug-14 0:19am
v2

1 solution

 
Share this answer
 
Comments
@p@richit 27-Aug-14 5:43am    
Thanks for reply @Tadit ,but i can't able to understand the refered code. i am new in jquery. can you please help for the given code.
Rajeev did you read that answer? There is also an demo link. Go to that. You can see the code also.
@p@richit 28-Aug-14 0:09am    
I have tried.when i populate that code,auto-complete not working
Do you see any errors in console window of developer tool?

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