ahmed salah

ahmed salah

  • 1.2k
  • 547
  • 66.6k

How to display Employee Name when autocomplete change for employeeId?

Aug 23 2023 8:30 PM

I work on asp.net mvc auto complete project .I face issue I can't display EmployeeName on input text Id LineManagerName when change auto complete employeeId

list of employeeid auto complete display success but I can't get employeename for selected employee id on input text LineManagerName

code working success and auto complete working perfect only need to display Employee Name when employeeId changed

 

@Html.EditorFor(model => model.LineManager, new { htmlAttributes = new { @class = "form-control", id = "txtLineManagerId" } })
<input type="text" id="LineManagerName" class="form-control" /> 

public ActionResult GetAllEmployeeBasedSearchText(string searchText)
        {
            JDEUtility jde = new JDEUtility();
         
            List<object> employeeListCriteria = new List<object>();
            employeeListCriteria = jde.GetAllEmployeeBasedSearchText(searchText);
            return Json(employeeListCriteria, JsonRequestBehavior.AllowGet);

        }
       public static List<object> GetAllEmployeeBasedSearchText(string searchText)
        {
            OleDbConnection con = new OleDbConnection(connectionString);
        
            string query = "";

            query = "SELECT cast(EMP.YAAN8 as varchar(20)) as EmployeeID,EMP.YAALPH AS EmployeeName FROM CRPDTA.F060116 EMP WHERE cast(EMP.YAAN8 as varchar(20)) LIKE '%" + searchText + "%' WITH UR";


            List<object> ApplicationsDataValues = new List<object>();
            try
            {
                
                using (var command = con.CreateCommand())
                {
                    command.CommandText = query;
                    command.CommandType = CommandType.Text;


                    command.Connection.Open();

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            ApplicationsDataValues.Add(new
                            {
                                
                                EmployeeID = reader.GetFieldValue<string>(0) 

                            });
                        }
                        reader.Close();
                    }

                }
                con.Close();
                return  ApplicationsDataValues;  
            }
            catch (Exception e)
            {
                return new List<object>();
            }
        }

    $(document).ready(function () {
        $("#txtLineManagerId").autocomplete({
            source: function (request, response) {
                var searchText = $("#txtLineManagerId").val();
                console.log("search text" + searchText)
                $.ajax({
                    url: '@Url.Action("GetAllEmployeeBasedSearchText", "Resignation")',
                    data: { searchText: searchText },
                    method: "GET",
                    dataType: "json",
                    success: function (data) {
                   
                        response($.map(data, function (item) {
                            console.log("data is" + item.EmployeeID);
                            return { label: item.EmployeeID, value: item.EmployeeID };

                        }))

                    }
                });
            }
        });
    });

 


Answers (1)