asp.net ajax 智能提示建议,请高手帮忙看看
先贴代码:
aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="TextBox1"
ServicePath="ajaxtishi.asmx" CompletionSetCount="10" MinimumPrefixLength="1" ServiceMethod="GetTextList">
</cc1:AutoCompleteExtender>
</form>
</body>
</html>
asmx:
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
//引入空间
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
[WebService(Namespace = "http://192.168.1.786/ajaxtishi")]
//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//添加服务脚本(必须添,否则程序不能正常运行)
[System.Web.Script.Services.ScriptService]
public class ajaxtishi : System.Web.Services.WebService
{
public static string[] autoCompleteTextList = null;
public ajaxtishi()
{
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
//定义数组保存获取的内容
//private string[] autoCompleteWordList = null;
//两个参数“prefixText”表示用户输入的前缀,count表示返回的个数
//[WebMethod]
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public String[] GetTextList(string prefixText, int count)
{
///检测参数是否为空
if (string.IsNullOrEmpty(prefixText) == true || count <= 0) return null;
// 如果数组为空
if (autoCompleteTextList == null)
{
//读取数据库的内容
SqlConnection conn = new SqlConnection("server=192.168.1.185;database=ttxs;uid=sa;pwd=963852");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select Title from EduWare where Title like '" + prefixText + "%'", conn);
DataSet ds = new DataSet();
da.Fill(ds);
//读取内容文件的数据到临时数组
string[] temp = new string[ds.Tables[0].Rows.Count];
int i = 0;
foreach (DataRow dr in ds.Tables[0].Rows)
{
temp[i] = dr["Title"].ToString();
i++;
}
Array.Sort(temp, new CaseInsensitiveComparer());
//将临时数组的内容赋给返回数组
autoCompleteTextList = temp;
if (conn.State == ConnectionState.Open)
conn.Close();
}
//定位二叉树搜索的起点
int index = Array.BinarySearch(autoCompleteTextList, prefixText, new CaseInsensitiveComparer());
if (index < 0)
{ //修正起点
index = ~index;
}
//搜索符合条件的数据
int matchCount = 0;
for (matchCount = 0; matchCount < count && matchCount + index < autoCompleteTextList.Length; matchCount++)
{ ///查看开头字符串相同的项
if (autoCompleteTextList[index + matchCount].StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) == false)
{
break;
}
}
//处理搜索结果
string[] matchResultList = new string[matchCount];
if (matchCount > 0)
{ //复制搜索结果
Array.Copy(autoCompleteTextList, index, matchResultList, 0, matchCount);
}
return matchResultList;
}
}
问题是:我在文本框输入不出来提示。我调试web服务的代码可以查出来!请高手给看看