Web服务正在运行,但数据未显示在文本框中

问题描述:

任何人都可以帮助我,我已经被困在这里好几个小时了。



i拿了一个文本框并应用自动完成扩展程序并创建一个Web服务,但事情是当我运行应用程序文本框不显示结果时,虽然我的Web服务在我是Web服务时获取结果。任何人都可以帮助我吗?



这是我的HTML代码



can anyone help me, i'd been stuck in this for many hours.

i took a textbox and apply auto complete extender to it and create a web service, but the thing is when i am running application text box not displaying result, although my web services fetch the result when i am web service. Can anyone help me?

Here is my html code

<asp:UpdatePanel ID="UpdtPanel" runat="server">
    <ContentTemplate>
        <asp:TextBox ID="txtTerri" runat="server"></asp:TextBox>
        <asp:AutoCompleteExtender ID="txtTerri_AutoCompleteExtender" runat="server" TargetControlID="txtTerri"
            ServiceMethod="ReturnTerritory" ServicePath="~/MyService.asmx"
            MinimumPrefixLength="1" EnableCaching="true"
            CompletionInterval="1000" CompletionSetCount="10"
            CompletionListCssClass="autocomplete_completionListElement"
            CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
            CompletionListItemCssClass="autocomplete_listItem">
         </asp:AutoCompleteExtender>
    </ContentTemplate>
</asp:UpdatePanel>





这是我的CSS







Here is my CSS


.autocomplete_completionListElement
{
 visibility : hidden;
 margin : 0px!important;
 background-color : inherit;
 color : windowtext;
 border : buttonshadow;
 border-width : 1px;
 border-style : solid;
 cursor : 'default';
 overflow : auto;
 height : 200px;
 text-align : left;
 list-style-type : none;
}
.autocomplete_listItem
{
 z-index: 9999 !important;
 background-color : window;
 color : windowtext;
 padding : 1px
}

.autocomplete_highlightedListItem
{
 background-color: #ffff99;
 color: black;
 padding: 1px;
}







这是我的网络服务






Here is my web service

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Web.UI.WebControls;

/// <summary>
/// Summary description for MyService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 MyService : System.Web.Services.WebService {

    public MyService()
    {

        //Uncomment the following line if using designed components
        //InitializeComponent();
    }

    [WebMethod]
    public string[] ReturnTerritory(string prefix, int count)
    {
        using (NovartisModel.NovartisEntities cntxt = new NovartisModel.NovartisEntities())
        {
            var res = from q in cntxt.tblTerritory where q.Territory_Name.ToLower().StartsWith(prefix.ToLower()) select q.Territory_Name;
            List<string> responses = new List<string>();
            foreach(string item in res)
            {
                responses.Add(item);
            }
            return responses.ToArray();
        }
    }
}

Quote:

请注意,您可以使用您选择的名称替换GetCompletionList,但返回类型和参数名称和类型必须完全匹配,包括大小写。

Note that you can replace "GetCompletionList" with a name of your choice, but the return type and parameter name and type must exactly match, including case.



尝试下面


try below

[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static string[] ReturnTerritory(string prefixText, int count)
{
        using (NovartisModel.NovartisEntities cntxt = new NovartisModel.NovartisEntities())
        {
            var res = from q in cntxt.tblTerritory where q.Territory_Name.ToLower().StartsWith(prefixText.ToLower()) select q.Territory_Name;
            List<string> responses = new List<string>();
            foreach(string item in res)
            {
                responses.Add(item);
            }
            return responses.ToArray();
        }
}