Click here to Skip to main content
14,929,833 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello Friends,
I'm new to webservice's, I'm trying out autocomplete textbox using jquery. Following is code:
<html xmlns="">
<head  runat="server">
    <script src="../JQuery/JQuery.js" type="text/javascript"></script>
    <script type="text/javascript">
        function lookup(inputString) {
            if (inputString.length == 0) {
            else {
                    type: "POST",
                    url: "WebService.asmx/getClientName",
                    dataType: "json",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    success: function(data) {
                        if (data.length > 0) {
                            var datafromserver = data.d.split(",");
                            $("#suggestionList").html(datafromserver); 'LINE1
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
    <style type="text/css">
        font-family: Helvetica;
        font-size: 13px;
        color: #000;
        margin: 0px;
        padding: 0px;
        position: relative;
        left: 0px;
        margin: 0px 0px 0px 0px;
        width: 200px;
        background-color: #7845DD;
        -moz-border-radius: 7px;
        -webkit-border-radius: 7px;
        border: 2px solid #000;
        color: #fff;
    .suggestionList {
        margin: 0px;
        padding: 0px;
    .suggestionList li {
        margin: 0px 0px 3px 0px;
        padding: 3px;
        cursor: pointer;
    .suggestionList li:hover {
        background-color: #DD45CD;

    <form id="form1"  runat="server">
        <asp:TextBox ID="txtAutoComplete" runat="server">
    <div class="suggestionsBox" id="suggestions" style="display: none;"></div>
    <div class="suggestionList" id="autoSuggestionsList"></div>

When I run the page, the autocomplete dropdown is not working. Any idea where I'm going wrong?
Is there any issue at LINE1?

Thanks in advance
Updated 5-May-11 22:40pm

 //this way you cant get record from the dataBase
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    public class WebService1 : System.Web.Services.WebService
        SqlConnection Con;
        SqlCommand Cmd;
        string[] items;

        public string[] GetStateName(string prefixText)
                Con = new SqlConnection("Your Connection string");
                Cmd = new SqlCommand("sp_getValue", Con);
                Cmd.CommandType = CommandType.StoredProcedure;
                Cmd.Parameters.AddWithValue("@prefixText", prefixText);
                SqlDataAdapter da = new SqlDataAdapter(Cmd);
                DataTable dt = new DataTable();
                items = new string[dt.Rows.Count];
                int i = 0;
                foreach (DataRow dr in dt.Rows)
                    items.SetValue(dr["StateName"].ToString(), i);
            catch (Exception ex)
              throw ex;
            return items;
dhage.prashant01 5-May-11 8:51am
I'm not able to declare
SqlConnection Con;
SqlCommand Cmd;

I have used the namespace, still not able to declate those variables.
dhage.prashant01 6-May-11 4:36am
ThankU, really helped.
But i have another issue, my autocomplete is not working. I have pasted my code above in question.
dhage.prashant01 5-May-11 8:48am
Nice site, I'm not looking for readymade. I want to make my own code. Any idea?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900