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:
EDIT :
- Add to your css the following definition for the
highlight
class :.highlight { background-color: yellow }
. You can update it depending on your needs. - Include the jquery.highlight-3.js script in your page.
- To make thinks easy, put your datalist in a
<div id="searchResults">...</div>
tag. - 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
2009-03-03 07:23:26
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.
2009-03-03 07:40:39
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.
2009-03-03 08:15:51
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
2009-03-03 08:18:13