日期:2014-05-16  浏览次数:20416 次

使用 <ajaxtoolkit:autocompleteextender 控件 不能弹出 ?

这是 html  页面 代码  前台


<asp:textbox id="txtJobName" runat="server" CssClass="textbox" ontextchanged="txtJobName_TextChanged"></asp:textbox>
<ajaxtoolkit:autocompleteextender ID="AutoCompleteExtender1" runat="server"
TargetControlID="txtJobName" ServicePath="PositionSearch.asmx" 
ServiceMethod="GetCompletionList" 
CompletionListCssClass="CompletionList"                                               CompletionListItemCssClass="CompletionListItem" 
CompletionInterval="100"
CompletionSetCount="100"
EnableCaching="False"
CompletionListHighlightedItemCssClass="CompletionListHighlightedItem" 
Enabled="True"       
DelimiterCharacters="" 
UseContextKey="True"
MinimumPrefixLength="1"/>




后台:主要相给 ContextKey 属性传一个值,这个这个值 来查询相关的数据(一共两个参数,这是一个)

        protected void txtJobName_TextChanged(object sender, EventArgs e)
        {
            AutoCompleteExtender1.ContextKey = this.StdBranchLoader.GetSelectBranchItem().Value;
        }




PositionSearch.asmx  页面代码

        [System.Web.Services.WebMethod(true)]
        [System.Web.Script.Services.ScriptMethod]
        public string[] GetCompletionList(string prefixText, int count, string contextKey)
        {
            List<string> names = new List<string>();

            string SQL = string.Format(@"SELECT CODE,NAMES FROM dbo.CPCJOBCODE where JOBCODEID in(SELECT JOBCODEID FROM dbo.CPCJOBCODETODEPT WHERE DEPTID='{0}')
                   and NAMES like '%{1}%'", contextKey, prefixText);
            DataSet dataSetResult = SqlEntityHelp.ExecuteSQLForDst(SQL);
            int resultCount = dataSetResult.Tables[0].Rows.Count;
            if (resultCount > 0)
            {
                for (int i = 0; i < resultCount; i++)
                {

                    string item = AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem