So now we will see as to how to connect this control to database and fetch the data when the user enters a specific word or phrase.....
AutoComplete.aspx
Now let us see the code for web service that will help us in fetching the data..
AutoComplete.cs
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
[WebMethod]
public string[] SearchDB(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}
SqlConnection con = new SqlConnection("server=localhost;database=your database;uid=your username;pwd=your pwd");
string str = "select * from table where username like @prefixText";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(str, con);
da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
DataSet ds = new DataSet();
da.Fill(ds);
int cnt = ds.Tables[0].Rows.Count;
List
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
items.Add(ds.Tables[0].Rows[i]["UserName"].ToString());
}
return items.ToArray();
}
}
Stylesheet.css
/* AutoComplete highlighted item */
.autocomplete_highlightedListItem
{
background-color: #ffff99;
color: black;
padding: 1px;
}
/* AutoComplete item */
.autocomplete_listItem
{
background-color : window;
color : windowtext;
padding : 1px;
}
Now let's check out the result after running the application ..
NOTE:Please do comment regarding the article as it'll help me to write even more specifically..
7 comments:
Hello my name is Ivan.T collecting flags.Can you visit my blog,please?
Hi Ivan , what kinda flags ???
Run this program . But not get the answer. What is my mistake . Please help me
Hi Suguna ,
PLease post the complete code what you are trying , 'coz the code which i have written is working fine...
Hi,mr talib .........
need to know about .net frame work in a very simple language.
Can i even get the material through which i can learn about .net in simple way .all about .net ,need tp practice well in a short period of time.
Good work bro, Got a chance to visit ur blog..i didnt knew u carried out so beautifully ..I bookmarked it..It is very useful to keep it a handy :)
Post a Comment