I am trying to use the AjaxControlToolkit Autocompleteextender (for Visual Studio 2008 having ToolkitScriptManager) with values returned from database to be suggested. When I am returning a simple string array it is working fine. But when I am trying to pull data from the database, it is not working. Below is my web service code and the Autocompleteextender Html. When I am running the following without breakpoints no error is thrown but does not work. And when I put breakpoints I am getting javascript error "Microsoft JScript runtime error: Sys.ParameterCountException: Parameter count mismatch."
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class AutoComplete : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod]
public string[] GetAgentCompanyAutoCompleteList(string prefixText, int count, string contextKey)
{
//return new string[] { "aaaaaaa", "bbbbbb" };
string sql = string.Format("select distinct AgentCompany from Realtors where FK_CompanyID = {0} Order By AgentCompany", contextKey);
string[] items = new string[] { "" };
string cn = "Data Source=localhost;Initial Catalog=ABCD;Integrated Security=True";
using (SqlDataAdapter da = new SqlDataAdapter(sql, cn))
{
DataTable dt = new DataTable();
da.Fill(dt);
if (dt != null && dt.Rows.Count > 0)
for (int i = 0; i < dt.Rows.Count; i++)
items[i] = dt.Rows[i]["AgentCompany"].ToString();
}
return items;
}
}
<asp:TextBox ID="txtCompany" runat="server" MaxLength="256" Width="150px">/asp:TextBox>
<ajax:AutoCompleteExtender
ID="AutoCompleteExtender1"
runat="server"
EnableCaching="true"
MinimumPrefixLength="1"
TargetControlID="txtCompany"
ServicePath="~/AutoComplete.asmx"
ServiceMethod="GetAgentCompanyAutoCompleteList"
UseContextKey="true">
</ajax:AutoCompleteExtender>