ASP .Net 文本框 Textchanged 事件

发布于 2025-01-05 16:40:45 字数 251 浏览 1 评论 0原文

我有一个网页。我在页面中显示表格中的记录,比如说学生。我查询所有学生并将他们显示在网格中。我想使用文本框来过滤 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

装迷糊 2025-01-12 16:40:45

您必须使用 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

流殇 2025-01-12 16:40:45

如果您想使用特定的方法,您可能想展示一些您当前的代码。否则你就会有人告诉你他们会怎么做。

现在看起来像这样吗?

<asp:Textbox id="myTextbox" runat="server" onChange="txtChanged" AutoPostBack="true"/>

public void txtChanged(object sender, EventArgs e)
{
    //Get text from textbox
    string text = ((TextBox)sender).Text;

    //Do what ever it is you want to do to edit the text
    text = text.ToUpper();

    //Update the other textbox with this text
    txtMyText2.Text = text;
}

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?

<asp:Textbox id="myTextbox" runat="server" onChange="txtChanged" AutoPostBack="true"/>

public void txtChanged(object sender, EventArgs e)
{
    //Get text from textbox
    string text = ((TextBox)sender).Text;

    //Do what ever it is you want to do to edit the text
    text = text.ToUpper();

    //Update the other textbox with this text
    txtMyText2.Text = text;
}
羁〃客ぐ 2025-01-12 16:40:45

我认为最好、最干净的方法是使用 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

川水往事 2025-01-12 16:40:45

仅当您向服务器发送请求时才会触发 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 an OnKeyDown event (right with Schiavini).

櫻之舞 2025-01-12 16:40:45

您可以使用 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文