AutoCompleteExtender实现模乎查询
Aspx源码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %>
<!DOCTYPE html PUBLIC "-//W
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>模乎查询</title>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager runat="server" ID="ScriptManager1" EnablePartialRendering="true" />
<div>
<h3><u>实现模乎查询</u></h3>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<atlas:AutoCompleteExtender runat="server" ID="Extender1" MinimumPrefixLength="1" >
<atlas:AutoCompleteProperties Enabled="True" TargetControlID="TextBox1" ServiceMethod="GetFilteredList" ServicePath="WebService.asmx" />
</atlas:AutoCompleteExtender>
</div>
</form>
</body>
</html>
WebService源码
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// WebService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService {
public WebService () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string[] GetFilteredList(string prefixText)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("JS.xml"));
DataTable dt = ds.Tables[0];
DataView dv = dt.DefaultView;
ArrayList items = new ArrayList(dt.Rows.Count);
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRowView drv = dv[i];
if (drv["zjm"].ToString().ToLower().IndexOf(prefixText.ToLower() ) != -1)
{
items.Add(drv["mc"].ToString());
}
}
return (string[])items.ToArray(typeof(string));
}
}
XML文件
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<Table>
<zjm>
Xg</zjm>
<mc>西瓜</mc>
<SQL>
100元
</SQL>
</Table>
<Table>
<zjm>
xg</zjm>
<mc>小瓜</mc>
<SQL>
250元
</SQL>
</Table>
<Table>
<zjm>
mt</zjm>
<mc>馒头</mc>
<SQL>
125元
</SQL>
</Table>
<Table>
<zjm>
dj</zjm>
<mc>豆角</mc>
<SQL>
254元
</SQL>
</Table>
<Table>
<zjm>
hd</zjm>
<mc>红豆</mc>
<SQL>
75元
</SQL>
</Table>
<Table>
<zjm>
hm</zjm>
<mc>红米</mc>
<SQL>
75元
</SQL>
</Table>
<Table>
<zjm>
ddn</zjm>
<mc>大豆泥</mc>
<SQL>
10075元
</SQL>
</Table>
</NewDataSet>
《asp.net core精要讲解》 https://ke.qq.com/course/265696
《asp.net core 3.0》 https://ke.qq.com/course/437517
《asp.net core项目实战》 https://ke.qq.com/course/291868
《基于.net core微服务》 https://ke.qq.com/course/299524