AutoComplete using Handler

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

add This to Script

<script src="" type="text/javascript"></script>
       <script src=; 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)
        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
            Return False
        End Get
    End Property
 End Class

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s