using System;using System.Web;using System.Collections;using System.Web.Services;using System.Web.Services.Protocols;using System.Collections.Generic;using MySql.Data.MySqlClient;/// <summary>/// Summary description for acPatientList/// </summary>[WebService(Namespace = "http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]public class acPatientList : System.Web.Services.WebService { public acPatientList () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string[] GetPatientList(string strPrefixText) { MySqlConnection cnDBConnection = new MySqlConnection(); MySqlCommand cmPatientList = new MySqlCommand(); MySqlDataReader rdPatientList; List <string> result = new List<string>(); cnDBConnection.ConnectionString = clsFunction.strConnection; cnDBConnection.Open(); cmPatientList.Connection = cnDBConnection; cmPatientList.CommandText = "SELECT patientid, CONCAT(lname,', ',fname,' ',mname) AS patient " + "FROM patientlist WHERE lname LIKE '" + clsFunction.ReplaceString(strPrefixText) + "%'"; rdPatientList = cmPatientList.ExecuteReader(); while(rdPatientList.Read()) { result.Add(rdPatientList[0].ToString() + "-" + rdPatientList[1].ToString()); } rdPatientList.Close(); cmPatientList.Connection.Close(); cnDBConnection.Close(); return result.ToArray(); } }
<asp:ScriptManager ID="ScriptManager" runat="server"> <Services> <asp:ServiceReference Path="acPatientList.asmx" /> </Services> </asp:ScriptManager> <cc1:AutoCompleteExtender ID="AutoCompleteExtender" runat="server" ServiceMethod="GetPatientList" ServicePath="acPatientList.asmx" MinimumPrefixLength="1" TargetControlID="txtPatientName" CompletionSetCount="10" EnableCaching="true"> </cc1:AutoCompleteExtender> <asp:Label ID="Label1" runat="server" Text="Request ID:" Width="87px"></asp:Label><asp:TextBox ID="txtRequestID" runat="server" BackColor="White" Font-Bold="True" ReadOnly="True"></asp:TextBox> <br /> <asp:Label ID="Label3" runat="server" Text="Patient Name:" Width="87px"></asp:Label><asp:TextBox ID="txtPatientName" runat="server" Width="303px" BackColor="White"></asp:TextBox><br /> <asp:Label ID="Label4" runat="server" Text="Requested By:" Width="87px"></asp:Label><asp:TextBox ID="txtRequestedBy" runat="server" Width="303px" BackColor="White"></asp:TextBox> </div>