<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" tagprefix="ajaxToolkit"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="AutoCompleteTest.asmx" /> </Services> </asp:ScriptManager> <div> <asp:TextBox ID="txtCountry" runat="server"></asp:TextBox> <ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="txtCountry" ServicePath="AutoCompleteTest.asmx" ServiceMethod="GetCountriesList" MinimumPrefixLength="1" EnableCaching="true" /> </div> </form> </body> </html>
using System; using System.Collections.Generic; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Data; using System.Data.SqlClient; using System.Configuration; /// <summary> /// Summary description for AutoCompleteTest /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class AutoCompleteTest : System.Web.Services.WebService { public AutoCompleteTest () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string[] GetCountriesList(string prefixText) { DataSet dtst = new DataSet(); SqlConnection sqlCon = new SqlConnection(ConfigurationManager.AppSettings["AppConnString"]); string strSql = "SELECT Name FROM Colleges WHERE Name LIKE '" + prefixText + "%' "; SqlCommand sqlComd = new SqlCommand(strSql, sqlCon); sqlCon.Open(); SqlDataAdapter sqlAdpt = new SqlDataAdapter(); sqlAdpt.SelectCommand = sqlComd; sqlAdpt.Fill(dtst); string[] cntName = new string[dtst.Tables[0].Rows.Count]; int i = 0; try { foreach (DataRow rdr in dtst.Tables[0].Rows) { cntName.SetValue(rdr["Name"].ToString(), i); i++; } } catch { } finally { sqlCon.Close(); } return cntName; } }
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class AutoCompleteTest : System.Web.Services.WebService
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)