Equivalent to Replacing a Recordset Field in Classic ASP

mountainbiking
02-08-2007, 06:24 AM
This should be an easy one....

I have many labels in a FormView one of the labels I want to replace the whitespace (vbcrlf) with <br> to get proper formatting as the user initially entered into a textarea.

The string tha I had in Classic ASP is this:
<%= Replace(adoRs("Description"),vbCrLf, "<br>")%>

This works great, I am not having luck with getting my label formatted as such. It could be that I am placing the code against the wrong event within the FormView or something else that I may totally be missing.

Here is what I have and it doesn't work:


Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
Replace(DirectCast(FormView1.FindControl("DescriptionLabel"), Label).Text, vbCrLf, "<br />")
End Sub



I have also tried the replace line of code inside the load, and itemcommand events of the formview.

wayneph
02-08-2007, 10:15 AM
The problem is that Replace doesn't change the string. It just returns the results. You actually have to Return it to something...

DirectCast(FormView1.FindControl("txtLabel"), Label).Text = DirectCast(FormView1.FindControl("txtLabel"), Label).Text.Replace(vbCrLf, "<br />")

mountainbiking
02-08-2007, 10:53 AM
Thanks Wayne! I feel like an idiot! I was so involved in the DirectCast code that I overlooked the fact that I had to set the label equal to itself then do the replace.

:o

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum