Autocomplete textbox using jquery in asp net

preview_player
Показать описание
Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

Stored procedure to retrieve employee name suggestions

Create proc spGetStudentNames
@term nvarchar(50)
as
Begin
Select Name from tblStudents where Name like @term + '%'
End

using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Script.Serialization;

namespace Demo
{
public class StudentHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string term = context.Request["term"] ?? "";
List<string> listStudentNames = new List<string>();

string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("spGetStudentNames", con);
cmd.CommandType = CommandType.StoredProcedure;

SqlParameter parameter = new SqlParameter()
{
Value = term
};

cmd.Parameters.Add(parameter);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
listStudentNames.Add(rdr["Name"].ToString());
}
}

JavaScriptSerializer js = new JavaScriptSerializer();
context.Response.Write(js.Serialize(listStudentNames));
}

public bool IsReusable
{
get
{
return false;
}
}
}
}

c) images

Add a WebForm to the ASP.NET project. Copy and paste the following HTML and jQuery code.

<%@ Page Language="C#" AutoEventWireup="true"
Inherits="Demo.WebForm1" %>
<!DOCTYPE html>
<head runat="server">
<title></title>
<script type="text/javascript">
$(document).ready(function () {
$('#txtName').autocomplete({
});
});
</script>
</head>
<body style="font-family: Arial">
<form id="form1" runat="server">
Student Name :
<asp:TextBox ID="txtName" runat="server">
</asp:TextBox>
</form>
</body>
</html>
Рекомендации по теме
Комментарии
Автор

best one sir.. very well worked for me.. inspired from your work.. thinking to create our own channel to indian developes

sandeepvasuli
Автор

Really appreciate all the tutorials you've made. My wife believes I'm your greatest fan in Australia. This tutorial really helped out with something at work.

grantwilliams
Автор

Really Amazing Work by Venkat....Never seen such Tutorials on Youtube

Rahim
Автор

Autocomplete textbox using jquery in asp.net

Csharp-video-tutorialsBlogspot
Автор

best one and awesome, looking for this particular tutorial. Thanks for sharing

bawagrafix
Автор

Thank you - worked first time. For those having issues when using PlaceHolders, you need to append the reference of the ID of the textbox accordingly. My txtBox id = "txtSearchName", my placeholder ID is "ContentPlaceHolder1", therefore the JS call is: - Cheers!

Russellyeman
Автор

Thank you for all your generosity by sharing knowledge across the world. Would we be also getting few videos on Jquery Plugins...? It would be awesome to have them as well.

kunaldedhia
Автор

Thanks a lot sir, it is very to implement search in asp.net after watching this vd.

rajkumarchavan
Автор

Nope, this is not working for me. With the exception of the ADO using my database with different tables and column names, my code is identical. When I load the handler in the browser and add a term, it works fine. Just not on the textbox.

BigyetiTechnologies
Автор

Whatever the Text that is typed in the text box is not being passed as an argument to the generic handler....I have implemented the same code that is shown in the video.please help.

vamshikrishnabasani
Автор

Hi Venkat, really helpful.... so can the 1st record get select in the auto completed list once hit tab button

ganeshk
Автор

Hi Sir,

Hats off to you!!

Please post some videos on ANGULAR JS as well.

Thanks,

aamazingideasnational
Автор

The ashx is basically searching for the "term" in the query string and passing it as the input variable to the Stored Proc. The Jquery autocomplete function is taking the textbox text and sourcing it to the ashx handler which will search for the "term" variable in the query string. But where exactly are we assigning the textbox text into "term" variable ? the query string might have multiple variable passed, so how the handler function is identifying that as "term" ? or is it some default/automatic setup?

amland
Автор

Excellent tutorial. Thanks for posting. I tried to implement for a Content Page but the final step didn't work. everything was ok up to testing the Handler. What could be the issue?

ibrahimhammed
Автор

Thanks it worked for me with slight change in code by adding ClientID as below

ankitagarwal
Автор

I will try to explain this the best way I can. I am making a domain checker and that works for me, now I have a function that shows some of the domains I have in my var named "domains" once I type in a DOT 'because all the variables domains begin with a dot' all the domains will appear but when I write some text before I put the DOT it will not appear anymore. What do I have to change to let it show the text before the DOT? Here is the code I use, and some picture how it looks right now.

KoenBoyful
Автор

Thank You Sir, God Jesus Christ Bless you and your family

jesussheepakash
Автор

Hola Kudvenkat, estoy tratando de implementar el autocompletar del vídeo pero no logro entender por qué no funciona el Textbox, desde la Url funciona bien pero desde al formulario no hace nada, te agradezco la ayuda, creo que las librerías de jquery no están funcionado. estoy usando un <asp:Content ID="Content2" Runat="Server"> 
¿donde coloco el jquery?

gracias si me puedes dar una mano..

benjaminjaravacaly
Автор

Hi, Your code works excellent in web form without master page, but when i try to implement it to web form with master page, jquery doesn't work. Do You know why?

wojtekk
Автор

great work,

help me please, how to get the Id when I click on the Name on the TextBox?

aliabdouislem