auto complete asp.net
- by lodun
Why my autocomplete ajax script does not work:
This is my WebService.cs:
 using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Data.SqlClient;
using System.Collections.Generic;
  using System.Configuration;
using System.Web.Script.Services;
[ScriptService]
[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. 
public class WebService : System.Web.Services.WebService {
    public WebService () {
        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }
    [WebMethod]
    public string[] GetCountryInfo(string prefixText, int count)
{
 string sql = "Select * from questions Where username like @prefixText";
 SqlDataAdapter da = new SqlDataAdapter(sql,"estudent_piooConnectionString");
 da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
 DataTable dt = new DataTable();
 da.Fill(dt);
 string[] items = new string[dt.Rows.Count];
 int i = 1;
 foreach (DataRow dr in dt.Rows)
 {
  items.SetValue(dr["username"].ToString(),i);
  i++;
 }
 return items;
} 
}
my css:
    /*AutoComplete flyout */
.autocomplete_completionListElement
{
    margin : 0px!important;
    background-color : inherit;
    color : windowtext;
    border : buttonshadow;
    border-width : 1px;
    border-style : solid;
    cursor : 'default';
    overflow : auto;
    height : 200px;
    text-align : left;
    list-style-type : none;padding:0px;
}
/* AutoComplete highlighted item */
.autocomplete_highlightedListItem
{
    background-color: #ffff99;
    color: black;
    padding: 1px;
}
/* AutoComplete item */
.autocomplete_listItem
{
    background-color : window;
    color : windowtext;
    padding : 1px;
}
and textbox:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" CompletionListCssClass="autocomplete_completionListElement"
    CompletionListItemCssClass="autocomplete_listItem" CompletionSetCount="20"
CompletionInterval="1000"     DelimiterCharacters=";,:"
    CompletionListHighlightedItemCssClass="autocomplete_highlightedList MinimumPrefixLength="1" ServiceMethod="GetCountryInfo" ShowOnlyCurrentWordInCompletionListItem="true"   TargetControlID="TextBox2" ServicePath="WebService.asmx" runat="server"></cc1:AutoCompleteExtender>