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();
}