AJAX AutoCompleteExtender를 사용하여 asp.net 웹 페이지에 자동 완성 기능을 추가하려고합니다. 저장 프로 시저 (MS_SQL)를 통해이 작업을 수행 할 수 있기를 원하지만 예제를 찾을 수 없습니다. WebService를 만들었고 코드를 넣으려고 시도했지만 AJAX를 처음 사용했지만 아무 것도 작동하지 않는 것 같습니다.Ajax 자동 완성 저장 프로 시저 ASP.NET
SQL :
IF @Statement='AjaxSearch'
BEGIN
SELECT DISTINCT
a_AccomName
FROM SB_ACCOMMODATION
WHERE a_AccomName like @prefixText
END
C 번호 (WebserviceForAJAX.asmx.cs) :
using System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using AjaxControlToolkit;
using System.Web.Script.Services;
using System.Collections.Generic;
using System.Collections.Specialized;
namespace Atlas
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
//[System.ComponentModel.ToolboxItem(false)]
public class WebService1 : System.Web.Services.WebService
{
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static List<string> SearchCustomers(string prefixText, int count)
{
AtlasInterface conn = new AtlasInterface();
SqlCommand cmdStoredProcedure = new SqlCommand("ATLAS_ACCOMMODATION", conn.sbConn);
cmdStoredProcedure.CommandType = CommandType.StoredProcedure;
cmdStoredProcedure.Parameters.Add("@Statement", SqlDbType.Char).Value = "AjaxSearch";
cmdStoredProcedure.Parameters.Add("@prefixText", SqlDbType.Char).Value = prefixText;
conn.sbConn.Open();
List<string> customers = new List<string>();
using (SqlDataReader sdr = cmdStoredProcedure.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(sdr["a_AccomName"].ToString());
}
}
conn.sbConn.Close();
return customers;
}
}
}
HTML : 당신은 ASMX 웹 서비스를 생성하고 사용자가 설정 한
<asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender
ServiceMethod="SearchCustomers"
MinimumPrefixLength="1"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtContactsSearch"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false">
</cc1:AutoCompleteExtender>
쿼리가 제대로 작동합니까? '%'와일드 카드 문자가 보이지 않습니다. 거기에 넣어야 할 수도 있습니다. – Rohit
http : // www.c-sharpcorner.com/UploadFile/74107f/using-stored-procedure-in-autocomplete-extender-textbox-in-a /' – Rohit
고맙습니다. SQL의 Where 절에 와일드 카드를 추가했습니다. \t \t 'where a_AccomName like @prefixText +'% '' – TLCONE