Ajaxcontroltoolkit AutocompleteExtender超时相关

时间:2012-12-24 15:53:55

标签: ajaxcontroltoolkit autocompleteextender

我正在尝试使用AjaxControlToolkit Autocompleteextender(对于具有ToolkitScriptManager的Visual Studio 2008),并建议从数据库返回值。当我返回一个简单的字符串数组时,它工作正常。但是当我试图从数据库中提取数据时,它无法正常工作。下面是我的Web服务代码和Autocompleteextender Html。当我运行以下没有断点时,不会抛出任何错误但不起作用。当我放置断点时,我收到javascript错误“Microsoft JScript运行时错误:Sys.ParameterCountException:参数计数不匹配。”

[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>

0 个答案:

没有答案