废话不多说,今天试试atlas
1. 加入atlas 的 scriptManager 因为是后台直接调webservice 所以加上webservice的地址
<atlas:ScriptManager ID="scriptManager" runat="server">
<Services>
<atlas:ServiceReference Path="WebService.asmx" />
</Services>
</atlas:ScriptManager>
<input id="Text1" type="text" /><span id="Text1__autocomplete"></span>
<script type="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<components>
<label id="Text1" targetElement="Text1">
<behaviors>
<autoComplete serviceURL="WebService.asmx" serviceMethod="GetCompletionList" minimumPrefixLength="1" completionList="Text1__autocomplete" />
</behaviors>
</label>
</components>
<references>
</references>
</page>
</script>
[WebMethod]
public string[] GetCompletionList(string prefixText)
{
string temp = "";
List<string> suggestions = new List<string>();
if (prefixText != "")
{
string mySelectQuery = "SELECT ContactName FROM Customers where ContactName like '" + prefixText + "%'";
SqlConnection myConnection = new SqlConnection(@"server=ZTE-WUANCHENG\wuancheng_zte;database=Northwind;User ID=sa;password=;Persist Security Info=true;");
SqlCommand myCommand = new SqlCommand(mySelectQuery, myConnection);
myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader();
try
{
while (myReader.Read())
{
suggestions.Add(myReader.GetString(0));
temp = temp + myReader.GetString(0) + ", ";
}
}
finally
{
// always call Close when done reading.
myReader.Close();
// always call Close when done reading.
myConnection.Close();
}
}

return suggestions.ToArray();
}