使用 Ajax 控件在 asp.net 中使用 AutoSuggest
我正在尝试在 TextBox
中进行自动建议,并且我使用 Ajax
控件来执行此操作。我给电影数组一些值。我想通过使用用户用于登录网站的电子邮件 ID 过滤用户表来从数据库中提供该值。我无法将标签值调用到下面的方法中。我在页面加载期间将用户的电子邮件 ID 存储在标签中。帮助我做到这一点。
[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();
}
I am trying to do auto suggest in a TextBox
and I used Ajax
controls to do so. I am giving movies array some values. I want to give that value from the database by filtering the user table with the email Id that the User used to Login to the website. I am not able to call the Label value into the method below. I have stored the email id of user in label during page load. help me to do that.
[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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是 AJAX Control Toolkit,您可以在 此处查看示例< /a>.
我不确定标签是什么,但您需要设置
UseContextKey=true;
并指定ajaxToolkit:AutoCompleteExtender
在您的情况下,您可以添加将以下代码添加到 Page.Load:
If you are using the AJAX Control Toolkit you can see example here.
I am not sure what is the label about, but you need to set
UseContextKey=true;
and specify the context key for theajaxToolkit:AutoCompleteExtender
In your case you can add the following code to Page.Load:
这是因为 web 方法是静态的。加载页面时,将 AutoCompleteExtender 的上下文键设置为标签值(电子邮件 ID)。另外,请确保 UseContextKey 设置为 true。
It's because the web method is static. On the load of your page, set the context key for your AutoCompleteExtender to the label value (email id). Also, make sure that UseContextKey is set to true.