简体   繁体   中英

Force Value To Text of TextBox

I have a TextBox and I have Datatable. I give TextBox Suggetions with Datatable. So when we enter key it gives suggetions for keys typed .Now what I want is user shoud not type key if it is not in datatable.

For Example I have datatable with keywords of abc,abd,abe,abe . So user can type 'ab' in textbox but not 'ac' because ac is not in datatable.Is it possible??

You could use the AJAX control Toolkit's - Filtered Textbox: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/FilteredTextBox/FilteredTextBox.aspx

In the code-behind: you could read the data and specify the ValidChars property.

<ajaxToolkit:FilteredTextBoxExtender ID="ftbe" runat="server"
    TargetControlID="TextBox3"         
    FilterType="Custom"
    ValidChars="ab" />

You could also use the AutoComplete extender to get the suggestions: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx

I assume this is asp.net with C# code behind.

Just return false on the keypress event, when you are not happy with the new character.

Returning false, will cancel the event.

Some more ideas can be found at: http://www.codeproject.com/KB/aspnet/AutoComplete.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM