Ajax自动完成扩展器 [英] Ajax AutoComplete Extender

查看:62
本文介绍了Ajax自动完成扩展器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Web应用程序中使用自动完成扩展器.为此,我在当前的Web应用程序中创建了一个Web服务,并在该应用程序中添加了Web引用.但是它不起作用.
谁能帮帮我.请

I want to use autocomplete extender in my web application .for this i make a web service in my current web application and add web reference in the application .But its not working .
Can anyh one help me.please

推荐答案

好,步骤1:

制作您的WebService.在您的项目中,创建一个名为 Services 的文件夹(不是必需的,而是整洁的:P)右键单击并说添加->".新的Web服务.让我们称之为WSAutoComplete.现在使它看起来像这样:

Ok, step 1:

Make your WebService. In your project, create a folder called Services, (not a necessity, but neat :P) Right click and say Add -> New Web Service. Lets call it WSAutoComplete. Now make it look like this:

namespace Services
{
    /// <summary>
    /// Summary description for WSAutoComplete
    /// </summary>
    [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 WSAutoComplete : System.Web.Services.WebService
    {
        [WebMethod]
        [ScriptMethod]
        public string[] GetAutoCompleteList(string prefixText, int count)
        {
            return GetResults(prefixText, count);
        }
    }

    private string[] GetResults(prefixText, count)
    {
         //Do your logic here
         //Example
         List<string> items = new List<string>() {"bob", "steve", "jones", "andrew"};
         List<string> result = new List<string();>
         foreach (string s in items)
             if (s.StartsWith(prefixText))
                 result.Add(s);
         return result.ToArray();
    }</string></string></string>

(忽略此</string></string></string> ;,我不知道为什么文本编辑器会生成多数民众赞成????)

我出于时间目的故意省略了计数,您可以自己添加,只限制返回的结果量.

现在,在您的AutoCompleteExtender控件上:

(Ignore this </string></string></string>, I dont know why thats there being generated by the text editor???)

I purposely left out the count for time purposes, you can add that yourself, just limit the amount of results that you return.

Now, on you AutoCompleteExtender control:

<asp:TextBox id="txtMyTextBox" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender TargetControlID="txtMyTextBox" ServicePath="/Services/WSAutoComplete.asmx"CompletionInterval="500" MinimumPrefixLength="2" ServiceMethod="GetResults"

ID="autocomplete" runat="server"></asp:AutoCompleteExtender>



那应该工作100%!!!确保正确设置服务路径!在服务方法中放置一个断点,看看它是否被击中!如果没有,那么您的ServicePath或ServiceMethod参数可能存在问题



That should work 100%!!! Make sure you set up your service path correctly! Put a break point inside you service method and see if it gets hit! If it doesnt, then there is probably a problem with your ServicePath or ServiceMethod paramter


这篇关于Ajax自动完成扩展器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆