ASP .Net Textbox Textchanged event

Ozgur Dogus picture Ozgur Dogus · Feb 14, 2012 · Viewed 30.3k times · Source

I have a webpage. I show records from table, lets say, students in my page. I query all the students and show them in grid. I want to use a textbox for filtering the datagridview results. For example if the user types a in the textbox the grid will show only the students who has "a" in his/her name. I want to refresh the grid at the same time while textbox is being edited.

i have set the autopostback property of textbox to true, and i refresh the grid in textbox's textchanged event.But the textchanged event fires only after the textbox loses focus. How can I make it fire after user types just one character ? thanks.

Answer

Schiavini picture Schiavini · Feb 14, 2012

You have to use the onKeyDown event. However, I'd advise you to use ASP.NET AJAX or jQuery to load the results with Ajax.

Here is one example from asp.net: http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx

Another one, from Code project: http://www.codeproject.com/Articles/38803/Google-Like-Search-TextBox