私が使用している、自動提案にAsp.Net/C#
使用している私のページの1つで、以下は私が使用しているコードですAjax autocompleteextender
<Services>
<asp:ServiceReference Path="AutoCompleteSearchByName.asmx" />
</Services>
</asp:ScriptManager>
<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox>
<ajaxtoolkit:autocompleteextender runat="server" ID="autoComplete1"
TargetControlID="txtCountry" ServicePath="AutoCompleteSearchByName.asmx"
ServiceMethod="GetNames" MinimumPrefixLength="1" EnableCaching="true" />
ただし、デザインモードでは、エラーが発生します。エラーには、
Error creating control autocomplete1 , AutocompleteSearchByName.asmx could not be set on property ServicePath
これが私のAutoCompleteSearchByName.asmxコードです
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace CwizBankApp
{
/// <summary>
/// Summary description for AutoCompleteSearchByName
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 AutoCompleteSearchByName : System.Web.Services.WebService
{
[WebMethod]
public string[] GetNames(string prefixText)
{
DataSet dst = new DataSet();
SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["Server=Server;Database=CwizData;Trusted_Connection=True"]);
string strSql = "SELECT f_name FROM cust_master WHERE f_name LIKE '" + prefixText + "%' ";
SqlCommand sqlComd = new SqlCommand(strSql, sqlCon);
sqlCon.Open();
SqlDataAdapter sqlAdpt = new SqlDataAdapter();
sqlAdpt.SelectCommand = sqlComd;
sqlAdpt.Fill(dst);
string[] cntName = new string[dst.Tables[0].Rows.Count];
int i = 0;
try
{
foreach (DataRow rdr in dst.Tables[0].Rows)
{
cntName.SetValue(rdr["f_name"].ToString(), i);
i++;
}
}
catch { }
finally
{
sqlCon.Close();
}
return cntName;
}
}
}
誰かが私にこの問題を解決する方法を提案できますか?ありがとう