后台代码。using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Xml;
using System.Web.Script.Services;
using System.Data.SqlClient;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[ScriptService]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
public string[] FindDish(string prefixText,int count)
{
string strSql = "select DishName From Dish where DishName like '%"+prefixText+"%'";
string strConn="Data Source=LIBAOZHEN\\LIBAOZHENSQL;Initial Catalog=GrogshopWeb;User ID=liuliu;Password=liuliu7765";
SqlConnection conn=new SqlConnection(strConn);
conn.Open();
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter(strSql,conn);
da.Fill(ds,"ds");
DataTable dt=ds.Tables[0];
string[] result=new string[dt.Rows.Count];
for(int i=0;i<dt.Rows.Count;i++)
{
result.SetValue(dt.Rows[i][0],i);
}
conn.Close();
}}页面代码
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services >
<asp:ServiceReference Path="~/WebService.asmx"/>
</Services>
</asp:ScriptManager>
<br />
搜索框:<asp:TextBox ID="Key" runat="server" >
</asp:TextBox><asp:Button ID="Button1" runat="server"
Text="查询" />
<cc1:AutoCompleteExtender
ID="AutoCompleteExtender1"
runat="server"
TargetControlID="Key"
ServiceMethod="FindDish"
CompletionSetCount="3"
ServicePath="WebService.asmx"
MinimumPrefixLength="1"
CompletionInterval="1000"
Enabled="true"
>
</cc1:AutoCompleteExtender>
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Xml;
using System.Web.Script.Services;
using System.Data.SqlClient;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
//[ScriptService]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () { //如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
public string[] FindDish(string prefixText,int count)
{
string strSql = "select DishName From Dish where DishName like '%"+prefixText+"%'";
string strConn="Data Source=LIBAOZHEN\\LIBAOZHENSQL;Initial Catalog=GrogshopWeb;User ID=liuliu;Password=liuliu7765";
SqlConnection conn=new SqlConnection(strConn);
conn.Open();
DataSet ds=new DataSet();
SqlDataAdapter da=new SqlDataAdapter(strSql,conn);
da.Fill(ds,"ds");
DataTable dt=ds.Tables[0];
string[] result=new string[dt.Rows.Count];
for(int i=0;i<dt.Rows.Count;i++)
{
result.SetValue(dt.Rows[i][0],i);
}
conn.Close();
}}页面代码
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services >
<asp:ServiceReference Path="~/WebService.asmx"/>
</Services>
</asp:ScriptManager>
<br />
搜索框:<asp:TextBox ID="Key" runat="server" >
</asp:TextBox><asp:Button ID="Button1" runat="server"
Text="查询" />
<cc1:AutoCompleteExtender
ID="AutoCompleteExtender1"
runat="server"
TargetControlID="Key"
ServiceMethod="FindDish"
CompletionSetCount="3"
ServicePath="WebService.asmx"
MinimumPrefixLength="1"
CompletionInterval="1000"
Enabled="true"
>
</cc1:AutoCompleteExtender>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货