autocomplete怎么什么都不显示
我用的代码是这个网址请各位看下这个方法行不行
我再把自己的代码贴上 帮帮帮各位
还有有bug
代码有点多 不过很容易看 帮帮忙啦 其实我想找重点的 不过怕漏了什么 所以就贴全部了前台如下:
<%@ Page Title="" Language="C#" MasterPageFile="~/WebForms/xxxMasterPage.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ims.WebForms.usb.WebForm1" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphScript__" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentBody" runat="server">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
MinimumPrefixLength="2" ServiceMethod="GetCompleteList"
ServicePath="~/WebService1.asmx" TargetControlID="TextBox1">
</asp:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>web服务的文件 如下:是放在根目录下没放在appcode里面 这个没关系的 我前台写的就是根目录
一下和他的都一样就一个地方不一样
他的oec2003_AutoComplete.cs里面有个构造方法 而且里面注释掉了 无参的构造方法写不写都一样 不过他写的那个不知道什么意思 觉得还是我哪里属性搞错了
我用的是母版页 母版页里面有ScriptManager
就这么多了 小弟第一次刚入.net不久 各位们看看帮帮忙using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;
using System.Collections;namespace ims
{
/// <summary>
/// WebService1 的摘要说明
/// </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 WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
} /// <summary>
/// 获取数据的方法GetCompleteList
/// </summary>
//定义静态数组用于保存获取的数据
private static string[] autoCompleteWordList = null;
[WebMethod]
public String[] GetCompleteList(string prefixText, int count)
{
if (autoCompleteWordList == null)
{
string[] temp = File.ReadAllLines(Server.MapPath("~/App_Data/TextFile.txt"));
Array.Sort(temp, new CaseInsensitiveComparer());
autoCompleteWordList = temp;
} int index = Array.BinarySearch(autoCompleteWordList, prefixText, new CaseInsensitiveComparer());
if (index < 0)
{
index = ~index;
} int matchingCount;
for (matchingCount = 0; matchingCount < count && index + matchingCount < autoCompleteWordList.Length; matchingCount++)
{
if (!autoCompleteWordList[index + matchingCount].StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase))
{
break;
}
}
String[] returnValue = new string[matchingCount];
if (matchingCount > 0)
{
Array.Copy(autoCompleteWordList, index, returnValue, 0, matchingCount);
}
return returnValue;
}
}
}
我用的代码是这个网址请各位看下这个方法行不行
我再把自己的代码贴上 帮帮帮各位
还有有bug
代码有点多 不过很容易看 帮帮忙啦 其实我想找重点的 不过怕漏了什么 所以就贴全部了前台如下:
<%@ Page Title="" Language="C#" MasterPageFile="~/WebForms/xxxMasterPage.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ims.WebForms.usb.WebForm1" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphScript__" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="contentBody" runat="server">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
MinimumPrefixLength="2" ServiceMethod="GetCompleteList"
ServicePath="~/WebService1.asmx" TargetControlID="TextBox1">
</asp:AutoCompleteExtender>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>web服务的文件 如下:是放在根目录下没放在appcode里面 这个没关系的 我前台写的就是根目录
一下和他的都一样就一个地方不一样
他的oec2003_AutoComplete.cs里面有个构造方法 而且里面注释掉了 无参的构造方法写不写都一样 不过他写的那个不知道什么意思 觉得还是我哪里属性搞错了
我用的是母版页 母版页里面有ScriptManager
就这么多了 小弟第一次刚入.net不久 各位们看看帮帮忙using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;
using System.Collections;namespace ims
{
/// <summary>
/// WebService1 的摘要说明
/// </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 WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
} /// <summary>
/// 获取数据的方法GetCompleteList
/// </summary>
//定义静态数组用于保存获取的数据
private static string[] autoCompleteWordList = null;
[WebMethod]
public String[] GetCompleteList(string prefixText, int count)
{
if (autoCompleteWordList == null)
{
string[] temp = File.ReadAllLines(Server.MapPath("~/App_Data/TextFile.txt"));
Array.Sort(temp, new CaseInsensitiveComparer());
autoCompleteWordList = temp;
} int index = Array.BinarySearch(autoCompleteWordList, prefixText, new CaseInsensitiveComparer());
if (index < 0)
{
index = ~index;
} int matchingCount;
for (matchingCount = 0; matchingCount < count && index + matchingCount < autoCompleteWordList.Length; matchingCount++)
{
if (!autoCompleteWordList[index + matchingCount].StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase))
{
break;
}
}
String[] returnValue = new string[matchingCount];
if (matchingCount > 0)
{
Array.Copy(autoCompleteWordList, index, returnValue, 0, matchingCount);
}
return returnValue;
}
}
}
写的都一样可就是不出来