为什么我的自动填充ajax脚本不起作用:
这是我的WebService.cs:
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Script.Services;
[ScriptService]
[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.
public class WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string[] GetCountryInfo(string prefixText, int count)
{
string sql = "Select * from questions Where username like @prefixText";
SqlDataAdapter da = new SqlDataAdapter(sql,"estudent_piooConnectionString");
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 1;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["username"].ToString(),i);
i++;
}
return items;
}
}
我的css:
/*AutoComplete flyout */
.autocomplete_completionListElement
{
保证金:0px!important;
background-color:inherit;
color:windowtext;
border:buttonshadow;
border-width:1px;
边框式:坚固;
cursor:'default';
溢出:自动;
身高:200px;
text-align:left;
list-style-type:none; padding:0px;
}
/ *自动完成突出显示的项目* /
.autocomplete_highlightedListItem { background-color:#ffff99; 颜色:黑色; 填充:1px; }
/ *自动完成项* /
.autocomplete_listItem { 背景颜色:窗口; color:windowtext; 填充:1px; }
和文本框:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem" CompletionSetCount="20"
CompletionInterval="1000" DelimiterCharacters=";,:"
CompletionListHighlightedItemCssClass="autocomplete_highlightedList MinimumPrefixLength="1" ServiceMethod="GetCountryInfo" ShowOnlyCurrentWordInCompletionListItem="true" TargetControlID="TextBox2" ServicePath="WebService.asmx" runat="server"></cc1:AutoCompleteExtender>
答案 0 :(得分:1)