我正在使用VisualStudio 2017,C#,asp.net 4.6.1和AjaxToolKit 18.1.0
并使用以下代码:
default.asxp
<asp:TextBox ID="textBoxUserName" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ServiceMethod="GetAllUsers"
MinimumPrefixLength="1" CompletionInterval="100" EnableCaching="false"
CompletionSetCount="10"
TargetControlID="textBoxUserName" ID="AutoExtender1" runat="server"
FirstRowSelected="false">
</ajaxToolkit:AutoCompleteExtender>
default.aspx.cs
[System.Web.Services.WebMethod]
public static List<string> GetAllUser(string prefixText, int count)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Rows.Add("Anna");
dt.Rows.Add("Betty");
dt.Rows.Add("Charly");
dt.Rows.Add("David");
dt.Rows.Add("Debbie");
dt.Rows.Add("Donna");
dt.Rows.Add("Gary");
List<string> username = new List<string>();
username = dt.AsEnumerable().Select(x => x.Field<string>("Name")).ToList();
return username;
}
这就是我得到的...
问候 鲁本茨
答案 0 :(得分:0)
好,我找到了解决方法:
我刚刚改变了
public static List<string> GetAllUser(string prefixText, int count)
到
public List<string> GetAllUser(string prefixText, int count, string contextKey)
并将UseContextKey =“ true”添加到控件中...
瞧瞧!