Visual Basic .NET » Database Programming
Cannot get AutoComplete functionality to work -- sparkymark75 --


I'm adapting the autocomplete example posted at
http://munich.schwarz-interactive.de/autocomplete.aspx 
but using only 1 textbox as that's all that I require.

I keep gettting a javascript "AutoComplete is undefined" error when I enter any text into the textbox. Can someone help me out please?

AUTOCOMPLETE.ASPX
==========================================================

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="autocomplete.aspx.vb" Inherits="_Default"
EnableViewState="false" %>

"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd 
">



Autocomplete Test using Ajax.NET Pro




Staff Member:













AUTOCOMPLETE.ASPX.VB
==========================================================

Imports System.Data Imports System.Data.SqlClient

_
Partial Public Class _Default
Inherits System.Web.UI.Page
_
Public Function Search(ByVal searchString As String, ByVal count As Integer) As DataTable
Dim dt As DataTable = New DataTable()

dt.Columns.Add("StaffID", Type.GetType("integer"))
dt.Columns.Add("StaffName", Type.GetType("string"))

Dim conn As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("hrdb"))

Dim cmd As SqlCommand = New SqlCommand("SELECT Staff_Id,
(RTRIM(Surname) + ', ' + RTRIM(Known_as)) As Name FROM Staff WHERE
(RTRIM(Surname) + ', ' + RTRIM(Known_as)) LIKE @Name ORDER BY Surname,
Known_as", conn)
cmd.Parameters.AddWithValue("@Name", searchString & "%")

Try
conn.Open()

Try
Dim dr As SqlDataReader = cmd.ExecuteReader
Dim row As DataRow

While dr.Read()
If dr(0) Is DBNull.Value Or dr(1) Is DBNull.Value Then
Continue While
End If

row = dt.NewRow()

row("StaffID") = dr(0)
row("StaffName") = dr(1)

dt.Rows.Add(row)
End While
Finally
conn.Close()
End Try
Catch ex As Exception
Throw ex
End Try

Return dt
End Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Register Ajax.NET methods from this class
AjaxPro.Utility.RegisterTypeForAjax(GetType(_Default))
End Sub

End Class

[Submit Comment]Home