Click here to Skip to main content
16,007,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text in the DB:My new text is a good text.

I want "My new text" was as Bold style. But I have original text on my site (My new text is a good text). How I can make text format from DB?

Code how I show data:

<% foreach (var category in Model) { %><br />
<h2> <%: category.CategoryName %> </h2><br />
<% foreach (var service in category.Trd_TrodarService){%><br />
        <h5> <%: service.ServiceName %> </h5><br />
    <%} %><br />
<%} %>



Thank you.
Posted

By using the tag <%: ... %> the content is encoded to display the HTML with the tags visible on the browser and not being interpreted. If you have content in your DB in the form of:
"<b>My new text</b> is a good text."


using the <%: "<b>My new text</b> is a good text." %> will output this this on the browser:

<b>My new text</b> is a good text.

While using the tag <%= "<b>My new text</b> is a good text." %> will output this this on the browser:

My new text is a good text.

Problem with the first tag you used was that the HTML was encoded so it would be displayed, but not interpreted .

Regards,
Manfred
 
Share this answer
 
v4
Not entirely sure what you mean but I'll guess that you want to preserve the format of the data. One way might be to include, for instance, text or add some other tokens denoting the format in the string and parse them out.

You could also rewrite your code as (if appropriate):

<% foreach (var category in Model) { %>
    <strong><%: category.CategoryName %></strong>
<% } %>


Like the use of <%: for encoding; first time I've seen someone use it. :thumbsup:
 
Share this answer
 
v2
I have an answer:
<![CDATA[<%= category.CategoryName %>]]>

is it correct?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900