vba代码如果自动完成不起作用

时间:2014-02-27 15:52:00

标签: asp.net vb.net

我是VB.net的新手我希望从我的数据库中获取自动完成的名称列表。我正在尝试遵循以下example

但我的问题是它无法正常工作,我没有得到任何错误,任何人都可以告诉我我做错了什么。

我的home.aspx

<%@ Page Title="Home Page" Language="VB"  CodeFile="~/home.aspx.vb" AutoEventWireup="true" Inherits="_home"%>
<%@ 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">

</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ScripManager1" runat="server"/>

<asp:UpdatePanel ID="autoupdate" runat="server">
<ContentTemplate>


    <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>

                          <asp:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server" 
                  TargetControlID="txtSearch" ServiceMethod="GetList" MinimumPrefixLength="3"
                  UseContextKey="True" >
          </asp:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>



</form>
</body>
</html>

这是我的home.aspx.vb

Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Imports System.Threading
Imports System.Web.Services

Partial Class _Default
    Inherits System.Web.UI.Page

    <WebMethod()> _
    Public Shared Function GetCompletionList(ByVal prefixText As String, ByVal count As Integer, ByVal contextKey As String) As String()
        Try

            Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("Test").ConnectionString)
            con.Open()
            Dim cmd As New SqlCommand("select LoginName from users where LoginName like '@Name' +'%' ", con)
            cmd.Parameters.AddWithValue("@Name", prefixText)
            'Dim da As New SqlDataAdapter(cmd)
            'Dim dt As New DataTable()
            'da.Fill(dt)
            'Dim InviteSearchListresult As New List(Of String)()
            'For i As Integer = 1 To dt.Rows.Count
            '    InviteSearchListresult.Add(dt.Rows(i)(1).ToString())
            '    Next
            Dim result As New List(Of String)()
            Dim dr As SqlDataReader = cmd.ExecuteReader()
            While dr.Read()
                result.Add(dr("LoginName").ToString())
            End While

            Return (
        From m In result
        Where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase)
        Select m).Take(count).ToArray()
        Catch ex As Exception


        End Try
 End Function
End Class

请帮助解决此问题。

1 个答案:

答案 0 :(得分:0)

您的服务方法是 GetList ,但您的实际方法名称是 GetCompletionList

尝试获取方法名称以匹配并查看是否存在问题。你试图调用一个不存在的方法。