0

我正在尝试使用自动完成扩展器,当我开始在文本框中输入时,什么也没有发生(不建议)。任何想法为什么?我也不认为回头客。To Array 会起作用吗?

    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.ComponentModel
    Imports System.Data.SqlClient

    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the
    following line.
    ' <System.Web.Script.Services.ScriptService()> _
    <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ToolboxItem(False)> _
    Public Class AutoComplete1
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function GetCompletionList(prefixText As String, count As Integer) As String()
        Try
            Dim Con As SqlConnection
            Dim cmd As SqlCommand
            Con = New SqlConnection
                Con.ConnectionString = "Data Source=servername;Initial Catalog=Database;"
            Con.Open()

            cmd = New SqlCommand
            cmd.Connection = Con
            cmd.CommandText = "SELECT ID, School, Address1, Address2, City, State, Zip, TIN FROM tblschools Where School LIKE @School + '%'"
            cmd.Parameters.AddWithValue("@School", prefixText)
            Dim customers As List(Of String) = New List(Of String)
            Dim reader As SqlDataReader = cmd.ExecuteReader()

            While reader.Read
                customers.Add(reader("School").ToString 

            End While
            Con.Close()

            Return customers.ToArray
        Catch ex As Exception

        End Try

    End Function


    End Class





    <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0     Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

下面是aspx页面的设计:

<asp:ServiceReference Path="*.asmx" />


</Services>

    </asp:ToolkitScriptManager>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:AutoCompleteExtender ID="AutoCompleteExtender" runat="server" 
        DelimiterCharacters="" Enabled="True" ServicePath="~/AutoComplete.asmx"  
        ServiceMethod="GetCompletionList" TargetControlID="TextBox1">
    </asp:AutoCompleteExtender>
    </form>
</body>
</html>
4

0 回答 0