ajax auto complete extender....coding

Ankitsrist
Posted by Ankitsrist under ASP.NET AJAX category on | Points: 40 | Views : 1846
here i will explain how i have implemented ajax auto complete extender.....it is very useful for beginners nd m also fresher so i understand the problem which we generally face during programming...here is the .aspx page
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServicePath= "WebService.asmx" ServiceMethod="GetCountries" MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" TargetControlID="TextBox1">
</cc1:AutoCompleteExtender>


nd below is the webservice.asmx page which u can simply include by right click on ur website....
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]

public class WebService : System.Web.Services.WebService
{
public WebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}

Class1 db=new Class1 ();
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public List<string>GetCountries(string prefixText)
{
db.mycon ();
SqlCommand cmd = new SqlCommand("select * from stuloginstoreproc where name like @name+'%'", db.con );
cmd.Parameters.AddWithValue("@name", prefixText);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
List<string> CountryNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
CountryNames.Add(dt.Rows[i][1].ToString());
}
return CountryNames;
}
}


happy coding frnds

Comments or Responses

Login to post response