AJAX查询

前端之家收集整理的这篇文章主要介绍了AJAX查询前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

A。前台代码

<%@ 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

猜你在找的Ajax相关文章