首页 > 编程 > .NET > 正文

使用asp.net进行多关键字查询的例子

2024-07-10 13:11:29
字体:
来源:转载
供稿:网友

下面的代码演示了如何对一段文本进行多关键字查询并高亮显示,给自己做为一个小tip保留下
<%@ page language="c#" debug="false" strict="true" explicit="true" buffer="true"%>
<%@ import namespace="system" %>
<html>
<head>
<title></title>
</head>
<style type="text/css">
.highlight {}{text-decoration:none; font-weight:bold; color:white; background:blue;}
</style>
<body bgcolor="#ffffff" topmargin="0"  onload="document.forms[0].keywords.focus();">
<script language="c#" runat="server">
void page_load(object source, eventargs e)
{
labeltxt.text = "give the proper respect to hand-coding.you should both respect and loathe handwritten code. you should

respect it because there are often special cases integrated into code that are overlooked with a cursory inspection. when

replacing code you’ve written by hand, you need to make sure you have the special cases accounted for. you should loathe

hand-code because engineering time is extremely valuable, and to waste it on repetitive tasks is nearly criminal. the goal

of your generator should always be to optimize the organization’s most valuable assets.the creativity and enthusiasm of

the engineering team.";
}
public string highlight(string search_str, string inputtxt)
{
    regex regexp = new regex(search_str.replace(" ", "|").trim(), regexoptions.ignorecase);
    return regexp.replace(inputtxt, new matchevaluator(replacekeywords));
    regexp = null;
}
public string replacekeywords(match m)
{
    return "<span class=highlight>" + m.value + "</span>";
}
public void buttonclick(object sernder,system.eventargs e )
{
    labeltxt.text = highlight(keywords.text, labeltxt.text);
}
</script>
<h3></h3><br>
<form runat="server" method="post">
<asp:textbox id="keywords" runat="server"/>
<asp:button id="button" text="submit" runat="server" onclick="buttonclick"/><br><br>
<asp:label id="labeltxt" runat="server"/>
</form>
</body>
</html>

商业源码热门下载www.html.org.cn

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表