Formatting Multiline Text

G

Guest

I have read several posts regarding formatting multiline text for rendering
becuase vbCrLf needs to be converted to <br/> tags, and i need to do the
same. My question is the best way to achieve this - One of my pages is using
a detailview control on a Description datafield; what would be the best way
for me to format the Description field before its rendered?

Regards
Owen
 
G

Guest

Hi... I dont think i was really clear - i understand how to do the string
replace but not where. In my example i was displaying a detailview control
bound to my database, and trying to render the description field; Looking
through the code i dont know where its appropriate to run this function; I am
new to asp.net - I have created an template for my description field within
it i have the following code:

<asp:Label ID="Label2" runat="server" Text='<%# Bind("description")
%>'></asp:Label>

and i literally dont know what to do with it.... do I have to do something
create a prerender function for Label2? if so how do i reference
label2.Text....? Alternatively do i have another event on the DetailView
control the page that i have to trap? I want to just change this one field in
the most simple clean way possible.

Kind Regards
Owen
 
T

Todd

There's several ways to do this, but try this. Add a function in the
code behind, something like...


Function MyFunc(MyVal as String) as String
return Replace(MyVal, vbcrlf, "<br>")
End Function

Then on the aspx page itself, change your bind tag to....

<asp:Label ID="Label2" runat="server" Text='<%#
MyFunc(Eval("description") )%>'></asp:Label>

Or if you have other things to convert, build a conversiob class and
call the class from the function.

HTH

Todd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top