ASP Net Text box with Google like dropdown search values - c#

I am looking for a textbox in C# which should work like dropdown search values when I type anything in the textbox. Those values will come from calling a method.. and I Should be able to select any of the values.
Do i need to use the asp dropdownlist or is there any other sample code available which could help me.

You should look into jQuery autocomplete feature.
http://jqueryui.com/autocomplete/

The ajax control toolkit provides Autocomplete extender to do just that. The control calls a method, which you specify, asynchronously and get all the values to be shown as an option. I would imagine these values would be retrieved when the page loads and will not be session specific so can be stored in a cache for faster retrieval.
http://www.asp.net/AjaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx

Related

how to handle TextBox.KeyPress event in asp.net using ajax

i want to create a web page with a textbox and a gridview.
as you type in the textbox i want the content of grid view to be retrieved from database according to the text of textbox.
i am also using ajax.
is there any way to get the text from textbox as user types in and pass it to the server side code?
i searched on google but the only thing i got was keypress event using jquery or java and display it using java again. but there was nothing about passing it to the code behind.
Thanks and pardon my poor English :(
In asp.net you can specify the AutoPostBack="true" on a textbox this will fire an postback after you lose focus of that TextBox, so not on every keystrike if you desire to have a postback on every keystrike you will have to implement some javascript knowledge.
Here you can find an example:
How do I make a Textbox Postback on KeyUp?
But I believe you are more interessted in a AutoCompleteBox maybe give this link a try:
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
As you said, you can use the java key press event. Then you can create an ajax request and ask the server for data.
You should make sure that the data you are requesting can be retrieved very fast, otherwise you would have a delay when typing. Maybe it's a better approach to fetch the whole result and filter it while typing.
A small example can be found here: Making a Simple Ajax call to controller in asp.net mvc
Other examples can be found with your friend google.com :-)

How to store ids with selections in AutoComplete AjaxControlToolkit ASP.NET?

I am implementing the Autocomplete textbox from AjaxControlToolkit in ASP.NET. The ServiceMethod allows me to call a function which will populate a string list with which to populate the autocomplete list that will display.
My question is, when I call the database, I would like to store an ID that corresponds with each selection, so that once it is selected by the user, I can easily look it back up in the database. I don't want to display it in parentheses next to the selection (ie. "John Smith (ID1234)", etc.)
Is there a way to do this so that the ID is 'hidden' so to speak within the Autocomplete box, and can be retrieved on selection? Should i use a different autocomplete box to accomplish this? Any help is greatly appreciated. Thanks!
This might answer your question
http://www.aspsnippets.com/Articles/Fetch-multiple-values-as-Key-Value-pair-in-ASP.Net-AJAX-AutoCompleteExtender.aspx

Dynamic Drop Down List ASP.net

How can I create a dynamic drop down list without using AutoPostBack. I ask because I just want to change the value of what the second drop down list displays and then the user clicks a button and it submits. But If I use AutoPostBack then it postbacks to page and runs code that shouldn't be run until that final box has been selected. (I use Postback in the other part of my program so using !IsPostBack isnt a option.) I looked at Javascript but ASP generates all of its controls names at runtime. What can I do? I have looked at the Ajax CascadingDropDown control but my problem with that is it contained in a XML file or a Database, I need this to be contained inside my Page. Any Ideas?
You can use the CascadingDropDown control from the AJAX Control Toolkit
Maybe this example will help? It's part of the ASP.NET AJAX Control Toolkit available here.
You can use AJAX to get the values for the second drop down list, based on the selected value of the first. Add a onchange event handler on the client-side to the first drop down list that makes the AJAX call and fills the second on success.

ASP dropdownlist city selector

I have an asp dropdownlist loaded with cities/countries. They are loaded directly in code
<asp:ListItem Value="MIA">Miami, Florida</asp:ListItem>
I would like to extend the control with Ajax in order to allow a user to start typing and show similar matching options from a dropdownlist below. Is this possible using this control and the hard coded values? Thanks!
The behaviour you describe is usually achieved by extending the textbox control rather than dropdownlist.
Microsoft has a lot of useful tutorials on its asp.net website; try this one: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx for a start.
If you want to write your own control, I have written a blog about some of the gotchas when adding values to a DropDownList via javascript
http://blog.runxc.com/post/2009/04/27/Using-jQuery-to-add-values-to-a-DropDownList-and-overcoming-ASPNET.aspx

Dragging & dropping items from one list to another in a ASP.NET page?

I would like to move items from one list to another on a page, and I'm pretty flexible about what type of a list it is. What's the best way to do that? ASP.NET Ajax? jQuery? Anything else?
There's a nice tutorial on CodeProject that covers dragging with ASP.NET and jQuery:
http://www.codeproject.com/KB/webforms/JQueryPersistantDragDrop.aspx
if you want to do this and PostBack instead of using AJAX to update your data based on from fields you'll need to get creative about what types of controls you use. Page validation will complain about ASP controls like dropdownlists, listboxes, etc. if they contain selected items that weren't in the list when it was rendered.
Better to use AJAX to send back your updates or use HTML controls like unordered lists or select added via javascript and stuff the selected data in another control that doesn't complain (hiddenfield) on PostBack. The alternative is turning off page validation and I don't think that's a good idea.
You can also might look at YUI Library, I'd say it implements Drag & Drop in a very simple and flexible way:
http://yuilibrary.com/yui/docs/dd/
There are a lot of examples etc...

Categories

Resources