我正在尝试传递一个附加参数,以便当用户从下拉列表中选择一个状态时,具有自动完成功能的文本框将仅显示它 = 所选状态的结果。由于某种原因,添加此功能时 getcompletionlist 未触发?
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, Contextkey As String) As String()
Try
Dim Con As SqlConnection
Dim cmd As SqlCommand
Con = New SqlConnection
'Dim test As String
'test = Contextkey
Con.ConnectionString = ""
Con.Open()
cmd = New SqlCommand
cmd.Connection = Con
cmd.CommandText = "SELECT NPI, [Entity Type Code], [Provider Last Name (Legal Name)], [Provider First Name], [Provider Business Mailing Address City Name] FROM NPIData WHERE [Provider Last Name (Legal Name)] LIKE @Provider + '%'"
cmd.Parameters.AddWithValue("@Provider", prefixText)
Dim customers As List(Of String) = New List(Of String)
Dim reader As SqlDataReader = cmd.ExecuteReader()
While reader.Read
customers.Add(reader("Provider Last Name (Legal Name)").ToString + ", " + reader("Provider First Name").ToString + ", " + reader("Provider Business Mailing Address City Name").ToString)
End While
Con.Close()
Return customers.ToArray
Catch ex As Exception
End Try
End Function
End Class
这是我的 aspx 自动完成代码:
<asp:TextBox ID="TextBox1" runat="server" Height="27px" Width="375px"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender" runat="server"
DelimiterCharacters="" Enabled="True" ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList" TargetControlID="TextBox1"
MinimumPrefixLength="2" UseContextKey="true" ContextKey="State">
</asp:AutoCompleteExtender>
Protected Sub StateDropDown_SelectedIndexChanged(sender As Object, e As EventArgs) Handles StateDropDown.SelectedIndexChanged
AutoCompleteExtender.ContextKey = StateDropDown.Text
End Sub