简体   繁体   English

ASP.NET web 页面的搜索框

[英]ASP.NET SearchBox for web page

so I have an empty web page, with a button and a Label, when the button is clicked the label is filled with data from my database.所以我有一个空的 web 页面,带有一个按钮和一个 Label,当单击该按钮时,label 会填充我数据库中的数据。 I am new to asp.net, so I would like to know is there any way I can add a search box in the page, that I can search for data that is displayed in the Label.我是 asp.net 的新手,所以我想知道有什么方法可以在页面中添加一个搜索框,我可以搜索 Label 中显示的数据。

Example: I have list of cities in the Label and I want to see where is the city LONDON.示例:我有 Label 中的城市列表,我想看看伦敦城市在哪里。

I will provide some images:我将提供一些图像:

在此处输入图像描述

在此处输入图像描述

A way to change style of a html element using javascript would be the following:使用 javascript 更改 html 元素样式的方法如下:

<input type="text" id="SearchBox" onInput="OnSearchTextDidChange()">

<ul>
<li id="London">London</li>
<li id="Paris">Paris</li>
<li id="Sweden">Sweden</li>
<li id="Europe">Europe</li> 
</ul>


<script>

htmlIds = ["London", "Paris", "Sweden", "Europe"];


function OnSearchTextDidChange(){
    var text = document.getElementById("SearchBox").value.toString();

    for(var i = 0; i < htmlIds.length;i++){
       if(htmlIds[i] == text){
            document.getElementById(htmlIds[i]).style.color = "yellow"; 
       }
       else{
            document.getElementById(htmlIds[i]).style.color = "black";
       }
}

}

</script>

Be aware that this solution is case-sensitive请注意,此解决方案区分大小写

make a an html input element, and handle the input from user with javascript:制作一个 html 输入元素,并使用 javascript 处理来自用户的输入:

<input type="text" onInput="OnSearchTextDidChange()">



<script>
function OnSearchTextDidChange(){
//do what you want when search text changes

}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM