<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="search.aspx.cs" Inherits="考试试题管理系统.search" %>
<%@ 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">
<div>
缩写词:<asp:TextBox ID="name" runat="server" Height="23px"
Width="166px"></asp:TextBox>
<br />
</div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" TargetControlID="name" ServicePath="WebService1.asmx" ServiceMethod="hello" MinimumPrefixLength="1">
</cc1:AutoCompleteExtender>
</form>
</body>
</html>
B WebService1.asmx代码
[WebMethod]
public string [] hello(string prefixText,int count)
{
sqlConnection conn = new sqlConnection(" server=8KQCDK6WIOTOHDM\\sqlEXPRESS; integrated security=true ;database=master");
sqlDataAdapter sda = new sqlDataAdapter("select * from test where name like '" + prefixText + "%' ",conn);
DataTable dt = new DataTable();
sda.Fill(dt);
List<String> list = new List<String>();
foreach (DataRow item in dt.Rows)
{
list.Add(item["name"].ToString());
}
return list.ToArray();
}
}
}
原文链接:https://www.f2er.com/ajax/165190.html