i have an input using the jquery autocomplete plugin. with this i want to return 5 results. I was making this happen by just entering 5 return results in the stored procedure that im using, but i want to remove duplicates, while still showing 5 results. im not sure the best way to go about doing this
here is my code behind for the callback page
Public Class SearchCallback
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Clear()
Dim searchText As String = Request("searchText")
Dim searchField As String = Request("searchField")
Dim dtCustomer As CustomerCollection = CustomerService.SearchRecords(searchText, searchField, "Contains", searchField, "Asc", CInt("1"), CInt("5"))
Dim returnString As String
If searchField = "Company" Then
For Each drCustomer As Customer In dtCustomer
If returnString = "" Then
returnString = drCustomer.Company
else
returnString = returnString & "," & drCustomer.Company
End If
Next
Response.Write(returnString)
i had a list of more searchfield options after that to give me the data i want. Im putting the needed info into a string so i can use it with my javascript code as follows.
$(document).ready(function () {
$(".searchTextBox").autocomplete({
source: callback,
autoFill: true
});
});
var callback = function (request, response) {
var searchText = request.term;
var searchField = $(".ddlist > option:selected").attr("value");
$.ajax({
type: "GET",
dataType: "text",
url: "SearchCallback.aspx?searchText=" + searchText + "&searchField=" + searchField,
success: function (data) {
var splitData = data.split(",");
response(splitData);
}
});
}
everything works other then the duplication problem that im having.. please help!
its kinda messy but i got it working as i want with the following code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Response.Clear()
Dim searchText As String = Request("searchText")
Dim searchField As String = Request("searchField")
Dim lastValue As String
Dim resultsCounter As Integer = 0
Dim dtCustomer As CustomerCollection = CustomerService.SearchRecords(searchText, searchField, "Contains", searchField, "Asc", CInt("1"), CInt("100"))
Dim returnString As String
If searchField = "Company" Then
resultsCounter = 0
For Each drCustomer As Customer In dtCustomer
If returnString = "" Then
returnString = drCustomer.Company
lastValue = drCustomer.Company
resultsCounter += 1
ElseIf resultsCounter < 6 Then
If lastValue <> drCustomer.Company Then
returnString = returnString & "," & drCustomer.Company
lastValue = drCustomer.Company
resultsCounter += 1
End If
End If
Next
Response.Write(returnString)
What kind of ORM framework are you using? With SQL the DISTINCT keyword is used for this, that might help