what event should I hook to for this?

D

djc

I am using a repeater control to list 'detail' entries from a simple issue
tracking system. These detail entries are MSDE2000 TEXT fields. For each
one, I need to replace all the carriage return/line feeds with '<br/>' tags
before displaying so it maintains the users original readability as it was
input.

1) should I use the ItemCreated or the ItemDataBound event to do this? or
should I be using some other event?

2) I'm about to go lookup what vb.net functions I should use to do the
actual replacing work in the string. If someone could point me in the right
direction on that it would be appreciated as well.

any input is appreciated. Thanks.
 
S

Scott Allen

You could do this during ItemDataBound, or, call a method in the data
binding expression in the repeater, for example, I imagine you might
be using something like:

<%# DataBinder.Eval(Container.DataItem, "Detail") %>

Instead of using DataBinder, call your own method in code behind.
I have some examples here:
http://odetocode.com/Articles/278.aspx

HTH,
 
G

Guest

If you know you won't have more than 8000 characters in your field I would
just do the formatting in my SQL. It simplifies things greatly.

SELECT replace(cast(tpc_data_1 as varchar(8000)), char(13), '<BR/>') as
myColumn

Otherwise, I think either event will work and I'd use the Replace(cchar(13),
"<BR/>") function

HTH
 
D

djc

thank you for the reply. I like the SQL solution. But I can't garauntee <
8000 characters since its a TEXT field. I am looking at the replace method
now. Do you think I can just replace chr(13) and leave the following chr(10)
without issue? seems to work. I know windows puts chr(13) & chr(10)
(carriage return - linefeed) but other OS's do it differently.

thanks again.
 
D

djc

thanks.... I'll check out the link now.

Scott Allen said:
You could do this during ItemDataBound, or, call a method in the data
binding expression in the repeater, for example, I imagine you might
be using something like:

<%# DataBinder.Eval(Container.DataItem, "Detail") %>

Instead of using DataBinder, call your own method in code behind.
I have some examples here:
http://odetocode.com/Articles/278.aspx

HTH,
 
G

Guest

Yeah you could actually do another replace on the char(10) as well and just
replace it with an empty string. I don't think it's neccessary but you can do
it like this:

mystring = mystring.Replace(cchar(13), "<br/>").Replace(cchar(10), "")
 
D

djc

Thanks agian. I appreciate it.

ENIZIN said:
Yeah you could actually do another replace on the char(10) as well and just
replace it with an empty string. I don't think it's neccessary but you can do
it like this:

mystring = mystring.Replace(cchar(13), "<br/>").Replace(cchar(10), "")
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top