0

我正在尝试传递一个附加参数,以便当用户从下拉列表中选择一个状态时,具有自动完成功能的文本框将仅显示它 = 所选状态的结果。由于某种原因,添加此功能时 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
4

2 回答 2

0
Public Function GetCompletionList(ByVal prefixText As String,ByVal count As Integer,ByVal          contextKey As String) As String()
于 2013-06-27T14:34:32.513 回答
0

我知道评论晚了,但请在 webmethod 中将 ContextKey 更改为 contextKey,希望它会起作用

于 2016-12-13T08:01:19.927 回答