在asp.net中使用文本框和列表框进行搜索 [英] Search with textbox and listbox in asp.net
本文介绍了在asp.net中使用文本框和列表框进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我正在尝试执行搜索
当我在文本框中键入内容时,相应的主题应在列表框中突出显示
列表框在文本框下方.
我将asp.net与vb.net一起用作代码隐藏.
任何代码或想法都会有所帮助
hanks.
Hi all
I am trying to implement a search
when i type something in textbox the corresponding itmes should be highlighted in the listbox
listbox is below the textbox.
i am using asp.net with vb.net as codebehind.
Any code or idea would help
hanks.
推荐答案
Check these links
自动完成文本框 [ http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx [ ^ ]
http://csharpdotnetfreak.blogspot.com/2009/01/ajax-autocomplete-textbox- gridview.html [ ^ ]
问候
Prince Antony G
Check these links
AutoComplete Textbox[^]
http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx[^]
http://csharpdotnetfreak.blogspot.com/2009/01/ajax-autocomplete-textbox-gridview.html[^]
Regards
Prince Antony G
您需要使用Javascript.onkeyup
文本框事件调用一个函数,该函数将在列表框中搜索项目并将其突出显示
这是javascript
you need to use Javascript.onkeyup
event of textbox call a function which will search in listbox for items and make them highlighted
here is javascript
function SearchList()
{
var l = ;
var tb = document.getElementById('<%= TextBox1.ClientID %>');
for (var i=0; i < document.getElementById("listbox1").options.length; i++)
{
if (document.getElementById("listbox1").options[i].value.toLowerCase().match(tb.value.toLowerCase()))
{
document.getElementById("listbox1").options[i].selected = true;
return false;
}
else
{
ClearSelection();
}
}
}
function ClearSelection()
{
document.getElementById("listbox1").selectedIndex = -1;
}
按下按钮即可调用
call it from button press
<asp:textbox id="TextBox1" runat="server" onkeyup="return SearchList();" xmlns:asp="#unknown" />
这篇关于在asp.net中使用文本框和列表框进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文