WebService for TextBox AutoCompleteExtender

Last post 09-18-2008 5:39 PM by tagtech. 0 replies.

Sort Posts:

  • WebService for TextBox AutoCompleteExtender

    09-18-2008, 5:39 PM
    • Member
      20 point Member
    • tagtech
    • Member since 05-31-2006, 3:45 PM
    • Posts 31

    I'm new to Ajax, using VB2008 in ASP.net 3.5 VS2008 against SQL Server 2005.  I'm trying to get a textbox to populate a gridview with a list of potential returns which gets shorter with each user's keystroke.  My code works if I hit enter or add a button to click.  However, if I understand what I'm reading, the addition of the Ajax autocompletextender to my textbox should accomplish keystroke-by-keystroke data-listing and the reduction of the returned data.

    My problem is that in the code that follows, when the line of code

    suggestions.Add(dbDs.Tables(0).Rows(i - 1).Item(0).ToString)

    finishes and before the

    Next i

    executes, when the count is 20 (or whatever), I return to the textbox.  I don't see my error and I don't crash, but I don't get the results I expect.  I'd appreciate any help - thanks in advance.  My code follows:

    Imports System.Data.SqlClient

    Imports System.Data

    Imports System.Web

    Imports System.Web.Services

    Imports System.Web.Services.Protocols

    Imports System.Collections.Generic
    <WebService(Namespace:="http://tempuri.org/")> _

    <WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

    <System.Web.Script.Services.ScriptService()> _

    Public Class AutoCompleteInherits System.Web.Services.WebService

    <WebMethod()> _

    Public Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer) As String()

    'Create a Connection object

    Dim connObject As String = "Data Source=SCMD-XP-92;Initial Catalog=Northwind;Integrated Security=True providerName=System.Data.SqlClient"

    'Create a Select command to execute

    Dim dbGet As String = "SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle] FROM [Customers] WHERE ([CustomerID] LIKE @CustomerID + '%')"

    Dim suggestions As New List(Of String)

    'Create a DataSet to populate

    Dim dbDs As New DataSetFor i As Integer = 1 To count

    suggestions.Add(dbDs.Tables(0).Rows(i - 1).Item(0).ToString)

    Next i

    'Create a DataAdapter to connect

    Dim daSql As New SqlDataAdapter(dbGet, connObject)

    daSql.Fill(dbDs)

    Return suggestions.ToArray()

    End Function

    End Class

Page 1 of 1 (1 items)