tags:

views:

463

answers:

1

I found this http://forums.asp.net/p/1390512/2970477.aspx#2970477 as I searched for highlight search keyword in the returned result. But there is no solution or demo on how to accomplish that. I have similar problem like that post. Can anyone help look into that problem of the post above ?

+1  A: 

Let me google that for you :)

EDIT :

  1. Add to your css the following definition for the highlight class : .highlight { background-color: yellow }. You can update it depending on your needs.
  2. Include the jquery.highlight-3.js script in your page.
  3. To make thinks easy, put your datalist in a <div id="searchResults">...</div> tag.
  4. Generate a client script that will trigger on page load. For each word you want to highlight, you should execute the following javascript : $('#searchResults').highlight('yourWordHere'));

EDIT 2 :

Here is a sample server side code.

string keywords = keywordsTextBox.Text;
StringBuilder highlightScript = new StringBuilder();

foreach (keyword in keywords.Split(' '))
    highlightScript.AppendFormat("$('#searchResults').highlight('{0}'));", keyword);

ClientScript.RegisterStartupScript(GetType(), "highlightScript", highlightScript.ToString(), true);

We're no longer in the jquery field, I think you'll need to read a little bit more about asp.net application development.

ybo
Can you give a demo pls ? I found this http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html also but it's too generic.
Thanks a lot. I am trying. $('#searchResults').highlight('yourWordHere')); --> 'yourWordHere' is actually a keyword from a label in ASP.NET page. How to get the value from that label and put in in there ? $('#searchResults').highlight(ValueFromLabel)); Thanks a lot.
I get the keyword from the textbox and store in var and put in Label for later use like : Your result for [label] . I dont know how to get the value from the label and use it in the highlight function. Please show me a way. :D