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

      代码演示了如何对一段文本进行多关键字查询并高亮显示,给自己做为一个小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> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值