我已经尽力搜索我的代码中的错误,但我自己无法让自动完成扩展器工作。把招工广告。
这是我的代码:(摘 self 的 aspx 页面)
<asp:TextBox ID="TextBox1" Width="120px" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1" ServiceMethod="GetCompletionList" ServicePath="SearchAutoComplete.asmx" MinimumPrefixLength="1">
</cc1:AutoCompleteExtender>
我的网络服务代码:
[WebMethod]
public static string[] GetCompletionList(string prefixText, int count)
{
List<string> returnData = new List<string>();
MySqlConnection con = new MySqlConnection(Connection.ConnectionString());
string sql = "select title from blog where title like '%" + prefixText + "%'";
MySqlCommand cmd = new MySqlCommand(sql, con);
con.Open();
MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
while (reader.Read())
{
returnData.Add(reader["title"].ToString());
}
return returnData.ToArray();
}
最佳答案
如何解决这个问题:
注释掉您的 SQL 代码。只需返回一个包含一些测试数据的数组。那样有用吗?你看到了吗?如果不是,则不会调用您的网络服务代码。如果可行,那么您的问题出在您的数据库代码上……您的网络服务代码是否在调用页面上?
关于asp.net - 我怎样才能让我的自动完成扩展器工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/312318/