Click here to Skip to main content
14,983,791 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all ,

I have an autocomplete textbox .The list is being filtered properly but the label is showing as undefined. When I select the item, the value is binded. Please help


What I have tried:

<pre><script type='text/javascript'>
	    $(document).ready(function () {
	        var colors1 = '';
	        function customRenderItem(ul, item) {
	            var t = '' + item[0] + '' + item[1] + '',
                    result = $('<li class="ui-menu-item" role="menuitem"></li>')
                    .data('item.autocomplete', item)
                    .append('<a class="ui-corner-all" style="position:relative;" tabindex="-1">' + t + '</a>')
                    .appendTo(ul);
	            return result;
	        }
	        $("#search").mcautocomplete({
	            showHeader: true,
	            columns: [{ name: 'MRI NO', minWidth: '100px' }],
	            
	            source: function (request, response) {
	                $.ajax({
	                    type: "POST",
	                    contentType: "application/json; charset=utf-8",
	                    url: 'sample1.aspx/GetPatientAllDetails',
                    data: "{}",
                    dataType: "json",
                   
                    success: function (data) {
                       
                        response($.map(data.d, function (item) {
                            
                            return {
                              
                                "label": item.split('-')[1],
                                "value": item.split('-')[1],
                              
                                
                               
                            }
                           
                        }
                        

                        ))
                        
                        
                    },
                    error: function (response) {
                        alert(response.responseText);
                    },
                    failure: function (response) {
                        alert(response.responseText);
                    }
                });
                },
	            select: function (e, i) {
	               
	            },
	            minLength: 2
	    });

	    });
	</script>	

[WebMethod]
        public static string[] GetPatientAllDetails()
        {
            
            List<string> customers = new List<string>();
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = 
       ConfigurationManager.ConnectionStrings["HUIS_ConnectionString"].ConnectionString;
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = "SELECT TOP 2 IN027_02,IN027_03,IN027_05,IN027_27,IN027_17 from in027  group by  IN027_02,IN027_03,IN027_05,IN027_27,IN027_17 ";                    
                    cmd.Connection = conn;
                    conn.Open();
                    using (SqlDataReader sdr = cmd.ExecuteReader())
                    {
                        while (sdr.Read())
                        {
                            customers.Add(string.Format("{0}-{1}", sdr["IN027_03"], sdr["IN027_02"]));
                        }
                    }
                    conn.Close();
                }
            }
            return customers.ToArray();
        }
Posted
Comments
j snooze 9-Feb-21 17:42pm
   
Don't know what to tell you here, assuming that you have perhaps removed some code because I don't think you need data.d or the extra comma after the value.


Some working code I have is like this...

success: function (data) {
response($.map(data, function (item) {
return {
label: item.FullName,
value: item.FullName,
uid: item.Id
}
}));

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