Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function () {
- SearchText();
- });
- function SearchText() {
- $(".autosuggest").autocomplete({
- source: function (request, response) {
- $.ajax({
- type: "POST",
- contentType: "application/json; charset=utf-8",
- url: "code.aspx?Meth=AB&username=" + document.getElementById('txtSearch').value,
- data: "{}",
- dataType: "json",
- success: function (data) {
- var list = data;
- if (list.length > 0) {
- response($.map(list, function (item) {
- return {
- label: item.split(' ? ')[0],
- val: item.split('?')[1]
- }
- }));
- }
- else {
- response([{ label: 'No Records Found', val: -1}]);
- }
- },
- error: function (result) {
- alert("Error");
- }
- });
- },
- select: function (event, ui) {
- if (ui.item.val == -1) {
- return false;
- }
- //$('#lblUserId').text(ui.item.val);
- alert(ui.item.val);
- }
- });
- }
- public static List<string> GetAutoCompleteData(string username)
- {
- List<string> result = new List<string>();
- using (SqlConnection con = new SqlConnection("Data Source=192.168.1.42,1433;Initial Catalog=Harneedi;User ID=chaitanya_t;Password=makrotech"))
- {
- using (SqlCommand cmd = new SqlCommand("select specializationID,specialization,educationID from Mast_Specialization where specialization LIKE '%'+@SearchText+'%'", con))
- {
- con.Open();
- cmd.Parameters.AddWithValue("@SearchText", username);
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- // ID also display bcz of {1}
- //result.Add(string.Format("{0},{1}", dr["specialization"], dr["specializationID"]));
- result.Add(string.Format("{0},{1}", dr["specialization"], dr["specializationID"]));
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement