AutoComplete using Handler


<asp:textbox id=”txtAutoComplete” runat=”server”/>

add This to Script

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>
       <script src=http://dev.jquery.com/view/trunk/plugins/autocomplete/jquery.autocomplete.js; type="text/javascript"></script>
     <script type="text/javascript">
      $(document).ready(function () {
        $("#<%=txtAutoComplete.ClientID %>").autocomplete('select.ashx');
      });

 

Imports System.Web
Imports System.Web.Services

Public Class _select
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

        If Not [String].IsNullOrEmpty(context.Request.QueryString("q")) Then
            For Each s As String In GetAutoCompleteValues(context.Request.QueryString("q"))
                context.Response.Write(s + Environment.NewLine)
            Next
        End If

    End Sub
    Private Function GetAutoCompleteValues(ByVal prefixText As String)
        Dim db As New DataClasses1DataContext()
        Dim data = db.tblKitTemplateHeaders.Where(Function(n) n.CustomKitPartNumber.StartsWith(prefixText)).OrderBy _
            (Function(xe) xe.CustomKitPartNumber).Select(Function(c) c.CustomKitPartNumber).ToList()
        Return data
    End Function

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property
 End Class
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s