ASP .Net 文本框 Textchanged 事件
我有一个网页。我在页面中显示表格中的记录,比如说学生。我查询所有学生并将他们显示在网格中。我想使用文本框来过滤 datagridview 结果。例如,如果用户在文本框中键入 a,网格将仅显示姓名中包含“a”的学生。我想在编辑文本框的同时刷新网格。
我已将文本框的 autopostback 属性设置为 true,并且在文本框的 textchanged 事件中刷新网格。但是 textchanged 事件仅在文本框失去焦点后才会触发。用户只输入一个字符后如何让它触发?谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您必须使用 onKeyDown 事件。不过,我建议您使用 ASP.NET AJAX 或 jQuery 通过 Ajax 加载结果。
下面是来自 asp.net 的一个示例: http://www.asp.net/ ajaxlibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
另一项,来自代码项目:
http://www.codeproject.com/Articles/38803/Google-Like -搜索文本框
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
如果您想使用特定的方法,您可能想展示一些您当前的代码。否则你就会有人告诉你他们会怎么做。
现在看起来像这样吗?
You might want to show some your present code, if there is a particular method you want to go with for this. Otherwise your going to get a people telling you the way they would do it.
Does it look something like this right now?
我认为最好、最干净的方法是使用 Rad Controls,以下是如何执行此操作的示例:
http://demos.telerik.com /aspnet-ajax/controls/examples/integration/gridandcombo/defaultcs.aspx?product=grid
I think the best and most clean way is to use Rad Controls, here is an example on how to do it:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandcombo/defaultcs.aspx?product=grid
仅当您向服务器发送请求时才会触发
TextChanged
事件。如果您想在文本框中的文本更改时启动事件或创建函数,请使用OnKeyDown
事件(与 Schiavini 一起使用)。The event
TextChanged
only fires when you send a request to server. If you wanna launch an event or make a function when the text inside textbox changes, use anOnKeyDown
event (right with Schiavini).您可以使用 PicNet 在客户端而不是服务器中执行此操作,以获得更好的用户体验。您可以在这里找到它 http://www.picnet.com.au/resources/ tablefilter/demo.htm 请记住,Gridview 呈现为 HTML 表格,因此您可以自由地使用此 jQuery 插件。
祝你好运!
You can use PicNet to do this in the Client instead of the Server for a better User experience. You can find it here http://www.picnet.com.au/resources/tablefilter/demo.htm Remember that the Gridview is rendered as a HTML table, therefore you can freely use this jQuery plugin.
Good luck!