[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
string sql = "SELECT Firstname, Lastname FROM [Patient] Where Firstname like @prefixText or Lastname like @prefixText2";
SqlDataAdapter da = new SqlDataAdapter(sql, ConfigurationManager.ConnectionStrings["healthcareConnectionString1"].ToString());
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = "%" + prefixText + "%";
da.SelectCommand.Parameters.Add("@prefixText2", SqlDbType.VarChar, 50).Value = "%" + prefixText + "%";
DataTable dt = new DataTable();
da.Fill(dt);
string[] items = new string[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
items.SetValue(dr["Firstname"].ToString() + " " + dr["Lastname"].ToString(), i);
i++;
}
return items;
}
在 Default.aspx 中
<asp:ToolkitScriptManager
ID="ToolkitScriptManager1" runat="server" EnablePageMethods="true">
<asp:TextBox ID="TextBox1" runat="server" Width="199px"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" TargetControlID="TextBox1"
runat="server" ServiceMethod="GetCompletionList" ServicePath="WebService.asmx" MinimumPrefixLength="1" UseContextKey="True">
</asp:AutoCompleteExtender>
我使用上面的代码进行自动完成,但它不会工作建议的数据没有出现。我的代码有问题吗?