Auto Complete help needed
I working with asp.net 2.0 and I am using JQuery autocomplete in application which is getting data from database through webservice. But I have problem that as the data is more than 2000 rows autocomplete throws an error message
Maximum length exceeded.
So for testing purpose I try with small amount of data and it start working. So now I think I should use Like Query in my webservice and only return top 10 data only. So what i need do is that whatever i type in textbox it should go to webservice and webservice with filter the data will send back to us. But how can I achieve this. I am using following codes
ASPX Page Code
- <script type="text/javascript">
- $(document).ready(function() {
- //Code to fetch
- $.ajax({
- type: "POST",
- url: "../AutoComplete.asmx/GetCompletionActorList",
- dataType: "json",
- data: "{}",
- contentType: "application/json; charset=utf-8",
- success: function(data) {
- $("input#actorList").autocomplete({
- source: eval(data)
- });
- },
- error: function(XMLHttpRequest, textStatus, errorThrown) {
- alert(textStatus);
- }
- });
- });
- </script>
WebService Code
- <WebMethod()> _
- Public Function GetCompletionActorList() As String
- Dim sbActor As New StringBuilder()
- Dim actorAPI As New ActorBLL
- Dim actor As Q8movies.ActorDetailDataTable = actorAPI.GetActorDetail()
- Try
- sbActor.Append("[")
- For i As Integer = 0 To actor.Rows.Count - 1
- sbActor.AppendFormat("'{0}',", actor.Rows(i).Item("ActorName"))
- Next
- 'Removes the extra ":"
- sbActor = sbActor.Remove(sbActor.Length - 1, 1)
- sbActor.Append("]")
- Catch ex As Exception
- 'Setup a breakpoint here
- 'to verify any exceptions raised.
- Dim exp As String = ex.ToString()
- End Try
- Return sbActor.ToString()
- End Function
In above webservice code I will add parameter to the function so it will return less records. I also want to work on the CSS of the auto complete so kindly help on this.