Search keyword highlight in ASP.Net

后端 未结 4 426
悲哀的现实
悲哀的现实 2021-02-04 17:23

I am outputting a list of search results for a given string of keywords, and I want any matching keywords in my search results to be highlighted. Each word should be wrapped in

4条回答
  •  梦毁少年i
    2021-02-04 17:57

    Use the jquery highlight plugin.

    For highlighting it at server side

    protected override void Render( HtmlTextWriter writer )
    {
        StringBuilder html = new StringBuilder();
        HtmlTextWriter w = new HtmlTextWriter( new StringWriter( html ) );
    
        base.Render( w );
    
        html.Replace( "lorem", "lorem" );
    
        writer.Write( html.ToString() );
    }
    

    You can use regular expressions for advanced text replacing.

    You can also write the above code in an HttpModule so that it can be re used in other applications.

提交回复
热议问题