In Aspx
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true">
<Services>
<asp:ServiceReference Path="~/WebServices/AutoComplete.asmx" />
</Services>
</asp:ScriptManager>
<asp:TextBox ID="txtName" TabIndex="3" runat="server" CssClass="TextBox"
Width="250px" MaxLength="100"></asp:TextBox>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" Enabled="true"
EnableCaching="true" MinimumPrefixLength="1" TargetControlID="txtName"
ServiceMethod="GetNames" ServicePath="~/WebServices/AutoComplete.asmx">
</cc1:AutoCompleteExtender>
In asmx.cs file
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Web.Script.Services;
using System.Data;
[ScriptService()]
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AutoComplete : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod()]
public string[] GetNames(string prefixText, int count)
{
ArrayList filteredList = new ArrayList();
MySQLConnection con = new MySQLConnection();
string qry = "SELECT column_name FROM table_name WHERE column_name LIKE '%" + prefixText + "%' ";
DataSet ds;
ds = con.getDataset(qry);
foreach (DataRow dr in ds.Tables[0].Rows)
{ if(dr["column_name"].ToString().ToLower().StartsWith(prefixText.ToLower()))
filteredList.Add(dr["column_name "].ToString());
}
con.closeConnection();
return (string[])filteredList.ToArray(typeof(string));
}
}
No comments:
Post a Comment