views:

48

answers:

1

Hi

I m retrieving a text from SQL DB based on the Search criteria i give and displaying in the Textbox in asp.net. I need to highlight the words given in the search criteria in the displayed text.

For example : If i give "need" all the word "need" in textbox that is retrieved and displayed should be highlight in yellow color. Provide me some code snippets too.

+3  A: 

An asp.net TextBox renders as either an html <input type="text"> or a <textarea> neither of which support formatting of the text inside.

If you were to display the text in a Label or LiteralControl it would be easy to just do a yourString.Replace(searchTerm, "<span style=\"color:yellow\">" + searchTerm + "</span>"); or something similar.

klausbyskov
With some clever css you can potentially make a div look like a textbox, but I agree.....you can't format the text inside an actual textbox.
jaltiere