AutoCompleteExtender 为什么没有反应呢?

onlyhe 2009-10-13 03:00:22
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server" Height="14px" Style="border-right: #6dabe3 1px solid;
border-top: #6dabe3 1px solid; font-size: 11px; border-left: #6dabe3 1px solid;
color: #21325e; line-height: 15px; border-bottom: #6dabe3 1px solid; font-family: Verdana, Tahoma, Arial;background-color: #ffffff" Width="200px"></asp:TextBox>


<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
CompletionSetCount="20"
MinimumPrefixLength="1"
ServiceMethod="GetWordList"
ServicePath="WebService.asmx"
TargetControlID="TextBox1"

ScriptPath="app_data\WebService.cs" FirstRowSelected="True"></cc1:AutoCompleteExtender>




using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Configuration;
using System.Collections.Generic;
using WebSites;


/// <summary>
/// AutoCompleteService_CustName 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService()]//关键引用
public class AutoCompleteService_CustName : System.Web.Services.WebService
{

private static string[] m_autoCompleteWordList = null;
public AutoCompleteService_CustName()
{

//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}

[WebMethod]
public string[] GetWordList(string prefixText, int count)
{
string strSQL = "SELECT title FROM Article ORDER BY id";
string con = "Data Source=202.97.181.108;Persist Security Info=True;User ID=sa;Password=LNSZFJFBsystem";
SqlConnection myCn = new SqlConnection(con);
SqlCommand cmd = new SqlCommand(strSQL, myCn);
try
{
myCn.Open();
SqlDataReader myReader = cmd.ExecuteReader();
ArrayList list = new ArrayList(count);
int i = 0;
while (myReader.Read())
{
list.Add(myReader.GetString(0));
i++;
}
if (m_autoCompleteWordList == null)
{
//string[] temp = File.ReadAllLines(Server.MapPath("~/common/word.txt"));
string[] temp = (string[])list.ToArray(typeof(string));
Array.Sort(temp, new CaseInsensitiveComparer());
m_autoCompleteWordList = temp;
}
int index = Array.BinarySearch(m_autoCompleteWordList, prefixText, new CaseInsensitiveComparer());
if (index < 0)
{
index = ~index;
}
int matchingCount;
for (matchingCount = 0; matchingCount < count && index + matchingCount < m_autoCompleteWordList.Length; matchingCount++)
{
if (!m_autoCompleteWordList[index + matchingCount].StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase))
break;
}
string[] returnValue = new String[matchingCount];
if (matchingCount > 0)
{
Array.Copy(m_autoCompleteWordList, index, returnValue, 0, matchingCount);
}
return returnValue;

}
catch (System.Data.SqlClient.SqlException e)
{
throw new Exception(e.Message);
}
finally
{
myCn.Close();
}
}
}
...全文
293 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
草根码农 2011-06-24
  • 打赏
  • 举报
回复
ScriptPath="app_data\WebService.cs" FirstRowSelected="True"></cc1:AutoCompleteExtender>


您这个ScriptPath应该改成 ServicePath 吧

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧