使用asp.net进行多关键字查询的例子
2008-02-22 09:33:18来源:互联网 阅读 ()
下面的代码演示了如何对一段文本进行多关键字查询并高亮显示,给自己做为一个小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>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:实现.NET应用程序的自动更新
下一篇:ASP.NET无限分类
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash