我拿了一个文本框并应用了自动完成扩展程序来创建一个Web服务,但是当它运行时,应用程序文本框不会显示结果,尽管我的Web服务会获取结果。
这是我的HTML代码:
<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:
.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;
}
这是我的网络服务:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Web.UI.WebControls;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[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();
}
}
}
答案 0 :(得分:0)
您是否尝试将WebMethod作为List()返回?
我相信它需要一个字符串列表而不是字符串数组。
[WebMethod()]
public list<string> ReturnTerritory(string prefix, int count)
{
...
}