asp.net ajax 智能提示建议,请高手帮忙看看

wangjinchang 2009-06-25 03:06:04
先贴代码:
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服务的代码可以查出来!请高手给看看
...全文
482 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xugan666 2011-01-09
  • 打赏
  • 举报
回复
我Remak一下。········
jsp_Servlet 2010-05-17
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;
using System.Collections;
namespace CSNT
{
/// <summary>
/// WebService_SearchList 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
//[System.Web.Script.Services.ScriptService]
public class WebService_SearchList : System.Web.Services.WebService
{

public string[] autoCompleteFileList=null;
//[WebMethod]
//public string Hello()
//{
// return "Hello Word";
//}
[WebMethod]
public string[] SearchList(string prefixText,int count)
{//检查参数是否为空
if (string.IsNullOrEmpty(prefixText) == true || count <= 0)
{
return null;
}
if(autoCompleteFileList==null)
{//获取FilePage文件夹下面的所有文件的文件名
DirectoryInfo di = new DirectoryInfo(Server.MapPath("FilePage"));
FileSystemInfo[] fsi = di.GetFileSystemInfos();
if (fsi == null || fsi.Length <= 0)
{
return null;
}
//将文件名称保存到临时数组中
string[] tempFileList=new string[fsi.Length];
for (int i = 0; i < fsi.Length;i++ )
{
tempFileList[i] = fsi[i].Name;
}
//对数组进行排序
Array.Sort(tempFileList, new CaseInsensitiveComparer());
autoCompleteFileList = tempFileList;
}
//定义二叉树搜索的起点
int index = Array.BinarySearch(autoCompleteFileList, prefixText, new CaseInsensitiveComparer());
if(index<0)
{//修正起点
index = ~index;// ~ 运算符对操作数执行按位求补运算,其效果相当于反转每一位
}
//搜索符合条件的文件名称
int matchCount = 0;
for (matchCount = 0; matchCount <= count && matchCount+index<autoCompleteFileList.Length;matchCount++ )
{//查看开头字符串相同的项
if(autoCompleteFileList[index+matchCount].StartsWith(prefixText,StringComparison.CurrentCultureIgnoreCase)==false)
{
break;
}
}
//处理搜索结果
string[] matchResultList=new string[matchCount];
if(matchCount>0)
{//复制搜索结果
Array.Copy(autoCompleteFileList,index,matchResultList,0,matchCount);
}
return matchResultList;
}
}
}

“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------

分析器错误
说明: 在分析向此请求提供服务所需资源时出错。请检查下列特定分析错误详细信息并适当地修改源文件。

分析器错误消息: 未能加载文件或程序集“Ajax Control Toolkit”或它的某一个依赖项。系统找不到指定的文件。

源错误:


[没有相关的源行]


源文件: 无 行: 0

程序集加载跟踪: 下列信息有助于确定程序集“Ajax Control Toolkit”无法加载的原因。


警告: 程序集绑定日志记录被关闭。
要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD)设置为 1。
注意: 会有一些与程序集绑定失败日志记录关联的性能损失。
要关闭此功能,请移除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。
怎么回事呢?
jayccx 2009-06-26
  • 打赏
  • 举报
回复
[System.Web.Services.WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
有在后面加()的吗??
只要在方法上标记 [WebMethod] 表示是一个web方法就行了

参数必须是string prefixText,int count
wangjinchang 2009-06-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 iuhxq 的回复:]
安装一个httpwatch跟踪一下通信内容

找不到的话到我的网站:www.svnhost.cn找
[/Quote]

什么东东!????、
iuhxq 2009-06-25
  • 打赏
  • 举报
回复
安装一个httpwatch跟踪一下通信内容

找不到的话到我的网站:www.svnhost.cn
wangjinchang 2009-06-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 spyking945 的回复:]
你前台js代码呢
既然返回了,没显示就说明你前台显示代码有问题
[/Quote]

我用的是ajax 控件啊!
Jarvis-Li 2009-06-25
  • 打赏
  • 举报
回复
你前台js代码呢
既然返回了,没显示就说明你前台显示代码有问题

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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