需要TextBox_TextChanged事件的帮助 [英] need help with TextBox_TextChanged event

查看:125
本文介绍了需要TextBox_TextChanged事件的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

i在我的网络表单ASP.net中有一个文本框和一个列表框,我想要的是当我开始在我的文本框中输入一个id时,列表框中充满了来自id的建议我的数据库表以我正在键入的数字开头

i只希望数据库表中的现有ID出现在列表框中

i试过这个bau它不起作用,列表框是空,请帮助



  protected   void  TextBox1_TextChanged( object  sender,EventArgs e)
{
SqlCommand cmd = new SqlCommand( 从navire中选择num,其中num =' + TextBox1。 Text + %',connect);
cmd.ExecuteNonQuery();
SqlDataReader reader = cmd.ExecuteReader();
// ListBox1.Items.Clear();
if (reader.HasRows)
{
while (reader.Read())
{
ListBox1.Items.Add(reader.GetString( 0 )。ToString());


}
}
}

解决方案

如果你只是显示ID作为建议,而不是尝试这样的事情

http:// www。 asp.net/ajaxlibrary/ajaxcontroltoolkitsamplesite/autocomplete/autocomplete.aspx


你真的,真的,不想这样做!



想想看:每次用户输入密钥时,都必须对服务器进行回发,服务器必须创建页面,处理文本更改,访问数据库,等待响应,将其格式化为HTML并将其发送回客户端。我,作为一个用户,我会感到无聊,并在其他地方关于第三个按键...

在客户端做到这一点! Javascript应该能够处理它: http://www.c-sharpcorner.com/UploadFile/5089e0/how-to-show-textbox-value-exit-in-database-using-javascript/ [ ^


为什么..为什么..为什么有人会做这样的事情?这是一个不好的做法。 (性能问题)



相反,我会说使用自动完成文本框

请参阅示例,

使用DataBase和AjaxControlToolkit自动完成 [ ^ ]

使用DataBase和AjaxControlToolkit进行自动完成 [ ^ ]

http://www.aspdotnet-suresh.com /2012/08/using-jquery-autocomplete-with-aspnet.html [ ^ ]



-KR

hello,
i have a textbox and a listbox in my web form ASP.net , what i want is whene i start typing an id on my textbox , the listbox get full of suggestions with ids from my database table that start with the numbers i'm typing
i want only existing ids from database table to appear in listbox
i tried this bau it is not working,the listbox is empty , please help

protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
    SqlCommand cmd = new SqlCommand("select num from navire where num = '"+TextBox1.Text+"%'", connect);
             cmd.ExecuteNonQuery();
            SqlDataReader reader = cmd.ExecuteReader();
            // ListBox1.Items.Clear();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    ListBox1.Items.Add(reader.GetString(0).ToString());
                   
                   
                }
            }
        }

解决方案

if you only display id as a suggestion than try something like this
http://www.asp.net/ajaxlibrary/ajaxcontroltoolkitsamplesite/autocomplete/autocomplete.aspx


You really, really, don't want to be doing that!

Think about it: each time your user types a key, a postback has to occur to the server, the server has to create the page, handle the text change, access the database, wait for the response, format it to HTML and send it back to the client. Me, as a user I would have got bored and gone elsewhere by about the third keypress...
Do it in the client! Javascript should be able to handle it: http://www.c-sharpcorner.com/UploadFile/5089e0/how-to-show-textbox-value-exit-in-database-using-javascript/[^] does some of the work.


Why.. Why.. Why anyone would do such thing?? It's a bad practice. (Performance issue)

Rather I'd say use AutoComplete Textbox.
See the examples,
AutoComplete With DataBase and AjaxControlToolkit[^]
AutoComplete With DataBase and AjaxControlToolkit[^]
http://www.aspdotnet-suresh.com/2012/08/using-jquery-autocomplete-with-aspnet.html[^]

-KR


这篇关于需要TextBox_TextChanged事件的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆