繁体   English   中英

使用 Ajax 控件的 asp.net 中的 AutoSuggest

[英]AutoSuggest in a asp.net using Ajax controls

我正在尝试在TextBox中进行自动建议,并使用Ajax控件来执行此操作。 我给电影数组一些值。 我想通过使用用户用于登录网站的 email Id 过滤用户表来从数据库中提供该值。 我无法将 Label 值调用到下面的方法中。 在页面加载期间,我已将用户的 email id 存储在 label 中。 帮助我做到这一点。

[System.Web.Services.WebMethodAttribute(),System.Web.UI.WebControls, System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
   // Create array of movies
    string[] movies = {"Joey", "Joester", "Joker", "Joeic", "Joic", "Shrek II"};

    // Return matching movies
    return (from m in movies where m.StartsWith(prefixText,StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
}

如果您使用的是 AJAX 控制工具包,您可以在此处查看示例。

我不确定 label 是什么,但您需要设置UseContextKey=true; 并为ajaxToolkit:AutoCompleteExtender指定上下文键

在您的情况下,您可以将以下代码添加到 Page.Load:

if(!Page.IsPostBack)
{
  AutoCompleteExtenderID.ContextKey = LabeWtihEmal.Text;
}

这是因为 web 方法是 static。 在加载页面时,将 AutoCompleteExtender 的上下文键设置为 label 值(电子邮件 ID)。 此外,请确保 UseContextKey 设置为 true。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM