I am beginner to ajax control. I am using AutoCompleteExtender Textbox. My project is not showing any error. It compiled successfully but textbox not displaying any autocomplete suggestions as i type.
Please tell me whats the error. I am using asp.net 3.5.
Here is Code :
default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
WebService :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
///
/// Summary description for AutoCompleteTextBox
///
[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.
// [System.Web.Script.Services.ScriptService]
public class AutoCompleteTextBox : System.Web.Services.WebService {
//public AutoCompleteTextBox () {
//Uncomment the following line if using designed components
//InitializeComponent();
//}
[WebMethod]
public string[] getProductList( string prefixText)
{
string conString = WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
SqlConnection con = new SqlConnection(conString);
string strQuery = "Select ProductName From Products Where ProductName LIKE '" + prefixText + "%'";
SqlCommand cmd = new SqlCommand(strQuery, con);
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
string[] countName = new string[ds.Tables[0].Rows.Count];
int i = 0;
try
{
foreach(DataRow dr in ds.Tables[0].Rows)
{
countName.SetValue(dr["ProductName"].ToString(),i);
i++;
}
}
catch(Exception err)
{
throw err;
}
finally{con.Close();}
return countName;
}
}
Sandeep ShekhawatPosted Jul 12, 2011, 11:47 AM
remove comment sign from above and write
[System.Web.Script.Services.ScriptService]
on top of program
sonal thosarPosted Jul 12, 2011, 12:28 PM