Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Carriage Returns in a datatable being converted to spaces 1

Status
Not open for further replies.

NoCoolHandle

Programmer
Apr 10, 2003
2,321
0
0
US
I have a datatable that contains information from a varchar field in SQL Server. This datatable is being bound to a textbox in one instance and a td tag via a repeater in another. Both bindings show the same behaviour.

When I return a record that has an ascii 13 (Carriage Return) in it, the carage return seems to be returned as a space.

I would really like it to display as a Carriage return.

Any ideas???

Thanks

Rob
 
You would probably need to Replace() the CR with the string &quot;<br />&quot;, certainly for the <td> tags.

You can't have a CR in a textbox - do you mean textarea?

--James
 
<snip> textbox - do you mean textarea?</snip>

an asp:textbox with textmode = muiltline
which of course becomes a textarea..

Ok, I can figure out the textbox thing.. now it looks like

txtDescriptionConflict.Text = dr(2).ToString.Replace(Chr(13), &quot;<br>&quot;)

But my brain is blocking on the repeater binding syntax..


<td>
<%# DataBinder.Eval(Container,&quot;DataItem.ProjectDescription&quot;) %>
</td>

Should I do the replace in my sql statement? Seems ugly.
Also, this seems to force an replace on insert or update as well, am I correct?

Rob
 
Have you tried:

Code:
<td>
<%# Replace(DataBinder.Eval(Container,&quot;DataItem.ProjectDescription&quot;), Chr(13), &quot;<br />&quot;) %>
</td>

I'm not entirely sure it will work but worth a go?

--James
 
James, my thanks and a star for that one!

Rob
Now to do the replace on the update or insert to get rid of those pesky <br> tags :)

 
Do your replace when you are binding everything in your ItemDataBound sub routine:

Private Sub Repeater1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemDataBound

[Replace code here]

End Sub
 
By the way, if you do it during your databound sub routine you don't have to worry about those &quot;pesky tags&quot; in your update and insert statements.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top