我确信这是一个简单的解决方案,但我在最后......
我有以下ASPX
<asp:TextBox ID="textVendorNameLookup" AutoPostBack="true" runat="server" Width="200px"
onFocus="this.select()"
Text=''></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="VendorNameAutoCompleteExtender" TargetControlID="textVendorNameLookup"
FirstRowSelected="false" runat="server" ServiceMethod="GetVendor" CompletionInterval="1"
EnableCaching="true" MinimumPrefixLength="1" UseContextKey="true" ServicePath="VendorLookupWebService.asmx">
</ajaxToolkit:AutoCompleteExtender>
以下ASMX
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml;
/// <summary>
/// Summary description for VendorLookupWebService
/// </summary>
[WebService(Namespace = "http://rouses.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class VendorLookupWebService : System.Web.Services.WebService
{
public VendorLookupWebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
//public string[] GetOrganization(string prefixText)
public static List<String> GetVendor(string prefixText)
{
var cmdText = "Select vmvnnm from dbmoto..apvendp where vmvnnm like @prefixText and vmasts = 'A'";
using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MAINConnectionString"].ToString()))
using (var cmd = new SqlCommand(cmdText, conn))
{
cmd.Parameters.Add(new SqlParameter("@prefixText", string.Format("%{0}%", prefixText)));
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
var Vendors = new List<string>();
if (dr.HasRows)
{
while (dr.Read())
{
Vendors.Add(dr["vmvnnm"].ToString());
}
}
conn.Close();
return Vendors;
}
}
}
但是当我在文本框中输入时,web服务没有被激活....
有什么想法吗?
答案 0 :(得分:1)
GetVendor函数必须与下面的签名完全匹配:
public string[] GetVendor(string prefixText, int count)
如上所述here:
返回类型和参数名称和 类型必须完全匹配,包括 情况下。