Web service Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Script.Services;
namespace Product
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class CustService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List GetAutoCompleteData(string name)
{
List result = new List();
using (SqlConnection con = new SqlConnection(@"Data Source=KARUKUVELRAJ-PC\SQLEXPRESS;Initial Catalog=Product;Integrated Security=True"))
{
using (SqlCommand cmd = new SqlCommand("select DISTINCT name from customer where name LIKE '%'+@SearchText+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", name);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(dr["name"].ToString());
}
return result;
}
}
}
}
}
Form.aspx.cs Code
$(function () {
$('#<%=txtName.ClientID%>').autocomplete({
source: function (request, response) {
$.ajax({
url: "CustService.asmx/GetAutoComplete",
data: "{ 'name':'" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (result) {
response(result.d);
},
error: function (result) {
alert('Error Occure');
}
});
}
});
});
Ashutosh GuptaPosted Dec 17, 2019, 12:45 PM
Roshan PatilPosted Dec 17, 2019, 12:24 PM
Salman BegPosted Dec 17, 2019, 8:22 AM
Farhan AhmedPosted Dec 17, 2019, 7:05 AM