AutoCompleteExtender不起作用

时间:2014-03-30 14:44:18

标签: asp.net ajax web-services autocomplete ajaxcontroltoolkit

我想使用AutoCompleteExtender

但它不起作用,我在网络服务中设置了一个断点,但它没有进入网络服务!!

<asp:TextBox ID="txt_empName" runat="server" Width="300px" ></asp:TextBox>
                                        <cc1:AutoCompleteExtender ID="txt_empName_AutoCompleteExtender" runat="server"
                                            CompletionListCssClass="autocomplete_completionListElement" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
                                            CompletionListItemCssClass="autocomplete_listItem" Enabled="True" MinimumPrefixLength="4"
                                            OnClientItemSelected="get_emp_num" UseContextKey="True" ServiceMethod="Get_Emp_AutoComplete"
                                            ServicePath="~/EmpAutoComplete.asmx" TargetControlID="txt_empName" BehaviorID="ACE_empName"
                                            EnableCaching="False">
                                        </cc1:AutoCompleteExtender>

我的网络服务:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 AutoComplete : System.Web.Services.WebService
{
    [WebMethod]
    public List<string> Get_Emp_AutoComplete(string prefixText, int count, string contextKey)
    {
        //split the string in the text box to get the department equivalent to the last prefix text entered in the textbox after ',' or ';'
        string[] s = prefixText.Split(new string[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length > 0)
        {
            prefixText = s[s.Length - 1].Trim();//Last item in the array
        }
        List<string> Emp_List = Get_RequestEmp(prefixText, contextKey);

        return Emp_List;
    }


    public static List<string> Get_RequestEmp(string prefixText, string contextKey)
    {
        prefixText = prefixText.Trim().Replace(' ', '%');
        DBConnection ConnectionObj = new DBConnection(CMSession.GetSession("code", HttpContext.Current), false);

        string  cmdText = "SELECT emp_num , trim(name) FROM grrt5emp WHERE name LIKE '%" + prefixText + "%' ORDER BY name";

        DataTable dt = ConnectionObj.Return_DataTable(cmdText);

        List<string> Emp_List = new List<string>();

        for (int i = 0; i < dt.Rows.Count; i++)
        {

            //Returning key-value pair
            Emp_List.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(dt.Rows[i][1].ToString(), dt.Rows[i][0].ToString()));
        }
        return Emp_List;
    }

}

我的AjaxToolkit版本是:

3.0.30930.28736

1 个答案:

答案 0 :(得分:0)

这对我有用:https://www.c-sharpcorner.com/UploadFile/57a357/autocomplete-extender-in-Asp-Net/ 我认为您只是想念asp:ScriptManager