I have this values in my tables. I used this code to display the values in autocomplete textbox but Order by not working
INSERT [dbo].[job_cylinder] ([id], [pid], [ppid], [posino], [unit]) VALUES (1, 15, NULL, N'72473-1B', 1)
INSERT [dbo].[job_cylinder] ([id], [pid], [ppid], [posino], [unit]) VALUES (2, 15, NULL, N'72473-2B', 2)
INSERT [dbo].[job_cylinder] ([id], [pid], [ppid], [posino], [unit]) VALUES (3, 15, NULL, N'72473-3B', 3)
INSERT [dbo].[job_cylinder] ([id], [pid], [ppid], [posino], [unit]) VALUES (4, 15, NULL, N'72473-4B', 4)
INSERT [dbo].[job_cylinder] ([id], [pid], [ppid], [posino], [unit]) VALUES (5, 15, NULL, N'72473-5B', 5)
INSERT [dbo].[job_cylinder] ([id], [pid], [ppid], [posino], [unit]) VALUES (6, 15, NULL, N'72473-6B', 6)
INSERT [dbo].[job_cylinder] ([id], [pid], [ppid], [posino], [unit]) VALUES (7, 15, NULL, N'72473-7B', 7)
INSERT [dbo].[job_cylinder] ([id], [pid], [ppid], [posino], [unit]) VALUES (8, 15, NULL, N'72473-8B', 8)
INSERT [dbo].[job_cylinder] ([id], [pid], [ppid], [posino], [unit]) VALUES (9, 15, NULL, N'72473-9B', 9)
INSERT [dbo].[job_cylinder] ([id], [pid], [ppid], [posino], [unit]) VALUES (10, 15, NULL, N'72473-10B', 10)
[WebMethod]
public static List<string> GetAutoCompleteData3(string searchTerm, string id)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=NERO-SIGBENU\\SQLEXPRESS01;Integrated Security=true;Initial Catalog=arpackaging;"))
{
using (SqlCommand cmd = new SqlCommand("select id,pid,posino from job_cylinder where pid=@Id" order by posino, con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", searchTerm);
cmd.Parameters.AddWithValue("@Id", id);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(string.Format("{0}/{1}", dr["posino"], dr["id"]));
}
return result;
}
}
}
function SearchText3() {
$(".autosuggest3").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Order.aspx/GetAutoCompleteData3",
data: "{ 'searchTerm': '" + request.term + "', id: '" + $('[id*=hfjobid]').val() + "'}",
dataType: "json",
success: function (data) {
if (data.d.length > 0) {
response($.map(data.d, function (item) {
return {
label: item.split('/')[0],
val: item.split('/')[1]
}
}));
}
else {
response([{ label: 'No Records Found', val: -1}]);
}
},
error: function (result) {
alert(result.responseText);
}
});
},
select: function (event, ui) {
if (ui.item.val == -1) {
return false;
}
$('[id*=hfcylinderid]').val(ui.item.val);
$(event.target).autocomplete("close");
setTimeout(function () {
$(event.target).blur();
});
},
minLength: 0
}).focus(function () {
$(this).autocomplete("search");
});
}