Trying to create a web service for auto complete extender. Saw some tutorials but can't get it to work
<ajx:AutoCompleteExtender ID="AC1" runat="server" ServiceMethod="FindItemId" MinimumPrefixLength="2" CompletionInterval="100" EnableCaching="false" CompletionSetCount="10" TargetControlID="TextBox1" FirstRowSelected="false" ServicePath="~/FindItemId.asmx"></ajx:AutoCompleteExtender>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for FindItemId
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[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 FindItemId : System.Web.Services.WebService
{
public FindItemId()
{
}
[WebMethod]
public static List<string> GetItemId(string prefixText, int count)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT ItemId FROM CoItems where ItemId like @SearchText + '%'";
cmd.Parameters.AddWithValue("@SearchText", prefixText);
cmd.Connection = conn;
conn.Open();
List<string> Items = new List<string>();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
Items.Add(sdr["ItemId"].ToString());
}
}
conn.Close();
return Items;
}
}
}
}<Services><asp:ServiceReference Path="~/FindItemId.asmx" /></Services>
How is it supposed to work?