I use this jquery for autocomplete. It works properly, but I don’t want display duplicate values. What should I do?
<script type="text/javascript">
$(document).ready(function () {
$("[id*=txtSearch1]").autocomplete({ source: '<%=ResolveUrl("~/DesktopModules/styPDashboard/Handler.ashx" ) %>' });
});
</script>
STY, [21.12.16 10:40] public class Handler : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
string prefixText1 = context.Request.QueryString["term"];
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select CompName from styComp_Profile where CompName like @txtSearch1 + '%' ";
cmd.Parameters.AddWithValue("@txtSearch1", prefixText1);
cmd.Connection = conn;
List<string> styComp_Profile = new List<string);
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
styComp_Profile.Add(sdr["CompName"].ToString());
}
}
conn.Close();
context.Response.Write(new JavaScriptSerializer().Serialize(styComp_Profile));
}
}
}
int[] array1 = { 1, 2, 2, 3, 4, 4 };
will yield only distinct elements.