<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>
[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; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)