TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
dhoni kholi
NA
198
42.7k
Autocomplete textbox not working Asp.net
Dec 17 2019 7:00 AM
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<string> GetAutoCompleteData(string name)
{
List<string> result = new List<string>();
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
<script type="text/javascript" src='https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js'></script>
<script type="text/javascript" src='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js'></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.css"/>
<script language="javascript" type="text/javascript">
$(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');
}
});
}
});
});
</script>
<asp:TextBox ID="txtName" runat="server" Font-Bold="False" CssClass="form-control"></asp:TextBox>
Reply
Answers (
4
)
Angular JS with Asp.net C#
Add event/scheduler calendar in mvc 3 application