HTML:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ 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">
WebService. CS:
Using system; using system. collections. generic; using system. LINQ; using system. web; using system. web. services; using system. data. sqlclient; using system. data; using system. web. script. services; // key Assembly reference /// <summary> /// Summary of WebService /// </Summary> [WebService (namespace = "http://tempuri.org/")] [webservicebinding (conformsto = wsiprofiles. basicprofile1_1)] // to allow ASP. net Ajax calls this web service from the script. Please cancel the comments to the downstream. [System. web. script. services. scriptservice] public class WebService: system. web. services. webService {public WebService () {// If the designed component is used, uncomment the following line // initializecomponent ();} [webmethod] [scriptmethod] Public String [] getproductname (string prefixtext, int count) {list <string> suggestions = new list <string> (); // declare a generic set sqlconnection con = new sqlconnection ("Server = juqi; database = northwind; uid = sa; Pwd = sa;"); con. open (); sqlcommand COM = new sqlcommand ("select distinct productname from products where productname like @ prefixname order by productname", con); COM. parameters. add ("@ prefixname", sqldbtype. nvarchar ). value = prefixtext + "%"; sqldatareader SDR = com. executereader (); While (SDR. read () {suggestions. add (SDR. getstring (0);} SDR. close (); con. close (); Return suggestions. toarray ();}}