Hello there,
I have been tasked with making a search function with an AutoComplete extender using AJAX and an SQL database.
I have some preliminary code written up that no longer gives me compiling errors, yet it doesn't fire when I try to invoke it (typing in the textbox).
Could I please have some assistance in getting this code to work or pointing me in the right direction? There are several tutorials on this matter and my code and all the infrastructure is similar except from the variables that I need to use. (Connection String etc.)
Also I am not too sure on the locations that the code I have written needs to be so I will include the location before each snippet.
Below is my code for the back end or .asmx file (Not .asmx.vb).
Code:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
<System.Web.Script.Services.ScriptService()><WebService(Namespace:="http://www.commpartners.us/webservices", Description:="Webservice to allow a autocompleter service lookup")><WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>Public Class PartnerList
Inherits System.Web.Services.WebService
<WebMethod(Description:="Method to retrieve Partner List")> Public Function GetPartnerList(ByVal prefixText As String, ByVal count As Integer) As Array
Dim SqlConnection1 As New SqlConnection(ConfigurationManager.AppSettings("NorthwindConnectionString"))
Dim SqlCommand1 As New SqlCommand("SELECT TOP & count.ToString() & * from Products WHERE ProductName like '& prefixText &%'", SqlConnection1)
SqlCommand1.Parameters.AddWithValue("nrows", count)
SqlCommand1.Parameters.AddWithValue("term", prefixText & "%")
Dim suggestions As New List(Of String)
SqlConnection1.Open()
Dim dr As SqlDataReader = SqlCommand1.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
suggestions.Add(dr(0).ToString)
End While
Return suggestions.ToArray
End Function
End Class
Here is my front end (.aspx) code
Code:
<asp:TextBox ID="searchtext" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
TargetControlID="searchtext" ServiceMethod="ProductList"
ServicePath="~/WebService.asmx" MinimumPrefixLength="1" CompletionInterval="500"></asp:AutoCompleteExtender>
<br />
<br />
<asp:LinkButton ID="LinkButton1" runat="server" >go</asp:LinkButton>
</div>
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/WebService.asmx" />
</Services>
</asp:ScriptManager>
Any help on this would be greatly appreciated.
Regards,
David