Example of Multi-Keyword query using asp.net

Source: Internet
Author: User
The following code demonstrates how to query multiple keywords in a text section and highlight it, keep yourself as a small 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 showould both respect and loathe handwritten code. You showould

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 shoshould loathe

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

Of your generator shocould always be to optimize the organization's most valuable assets. the creativity and enthusiasm

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>
<Asp: Label id = "LabelTxt" runat = "server"/>
</Form>
</Body>
</Html>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.