Advertisement
Guest User

Untitled

a guest
Feb 16th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. $(function () {
  2. SearchText();
  3. });
  4. function SearchText() {
  5. $(".autosuggest").autocomplete({
  6. source: function (request, response) {
  7. $.ajax({
  8. type: "POST",
  9. contentType: "application/json; charset=utf-8",
  10. url: "code.aspx?Meth=AB&username=" + document.getElementById('txtSearch').value,
  11. data: "{}",
  12. dataType: "json",
  13. success: function (data) {
  14. var list = data;
  15. if (list.length > 0) {
  16. response($.map(list, function (item) {
  17. return {
  18. label: item.split(' ? ')[0],
  19. val: item.split('?')[1]
  20. }
  21. }));
  22. }
  23. else {
  24. response([{ label: 'No Records Found', val: -1}]);
  25. }
  26.  
  27. },
  28. error: function (result) {
  29. alert("Error");
  30. }
  31. });
  32. },
  33. select: function (event, ui) {
  34. if (ui.item.val == -1) {
  35. return false;
  36. }
  37. //$('#lblUserId').text(ui.item.val);
  38. alert(ui.item.val);
  39. }
  40. });
  41. }
  42.  
  43.  
  44. public static List<string> GetAutoCompleteData(string username)
  45. {
  46. List<string> result = new List<string>();
  47. using (SqlConnection con = new SqlConnection("Data Source=192.168.1.42,1433;Initial Catalog=Harneedi;User ID=chaitanya_t;Password=makrotech"))
  48. {
  49. using (SqlCommand cmd = new SqlCommand("select specializationID,specialization,educationID from Mast_Specialization where specialization LIKE '%'+@SearchText+'%'", con))
  50. {
  51. con.Open();
  52. cmd.Parameters.AddWithValue("@SearchText", username);
  53. SqlDataReader dr = cmd.ExecuteReader();
  54. while (dr.Read())
  55. {
  56. // ID also display bcz of {1}
  57. //result.Add(string.Format("{0},{1}", dr["specialization"], dr["specializationID"]));
  58.  
  59. result.Add(string.Format("{0},{1}", dr["specialization"], dr["specializationID"]));
  60. }
  61. return result;
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement