程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> 使用asp.net進行多關鍵字查詢的例子

使用asp.net進行多關鍵字查詢的例子

編輯:.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> 
  
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved