Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'd be glad if someone could help with how to write a code for autocomplete TextBox in asp.vb.net.
I'm able to do that in VB.Net Windows application, but unable to do same in the Web Application. The following is what I've tried under Page_load:



VB
Try
            cmd = New SqlCommand("Select SubjectName from ProgramDetails.Subjects", cn)
            dr1 = cmd.ExecuteReader
            While dr1.Read
                txtSearch.AutoCompleteType.GetType.Name.Trim(dr1(0))
            End While
            dr1.Close()
            dr1 = Nothing
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
        End Try
Posted
Updated 21-Aug-18 9:22am
v2
Comments
ZurdoDev 28-Mar-13 10:28am    
It would be easier to use a jquery plugin to do it. There are lots of free ones already built that you can tie into.
Akaglo 28-Mar-13 10:30am    
Can you please show me that?

 
Share this answer
 
Comments
Akaglo 29-Mar-13 6:33am    
Thank you, Sir. I've checked the link, but that's not what I want exactly. For my problem, I want the data in the textbox to come from a table in the database.
Adam R Harris 29-Mar-13 16:19pm    
Take a look at the Remote, Remote JSONP and Remote with Cache examples .
They are exactly what you need
It seems like you are aiming for a server-side approach to implement an autocomplete feature. In ASP.NET web app, Page_Load event isn't the place to implement that. You would typically use the TextChanged event of the TextBox. But you should be careful when taking to this route as TextChange event causes the server to fire and trigger a postback and hits your database each time you change/type something in the TextBox. You could surely cache the data at once to reduce database calls but still you need to rebind your data control with the search results - which is kinda expensive.

Your closest option if you want to avoid doing some client-side scripting is using : AutoComplete Sample[^]

Here's an article that shows how to use it: AutoCompleteExtender in ASP.Net
[^]

The ideal way to implement an autocomplete feature is using a client-side approach with AJAX. You could use jQuery as already suggested by others and couple that with AJAX to communicate with your data from your database. Here's a great writeup about: Many ways to communicate with your database using jQuery AJAX and ASP.NET[^]

Once you get a good grasp on how the web works regarding communicating your data from the server to the client, then you can start working on your autocomplete feature. There are tons of examples in the net that are available. Here are a few of them:

TextBox AutoComplete with ASP.NET and jQuery UI | DotNetCurry[^]
Populate jQuery AutoComplete TextBox from Database using Web Service in ASP.Net
JQuery - Auto Complete Text Box In ASP.Net
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900