"Multiline Textbox input to database and display in html""wrap problem

i have one form in which i m using multiline textbox and entering data in it with line break . this multi line textbox has wrap property true and fixed width so when i m adding data in textbox it automatically wrap but when i m displaying data on aspx form it will not wrap as well as break line it will display as continuos text


<asp:textbox id="txtdetail" runat="server" wrap="true" width="220px"/>
in cs file

database input txtdetail.text

form display
<div style="widht:220px;display:block;overflow:hiddenl">
<%# DataBinder.Eval(Container.DataItem, "Description")%>
</div>

please help me to solve this issue
jbajajAsked:
Who is Participating?
 
GiftsonDJohnConnect With a Mentor Commented:
Try this

<div style="widht:220px;display:block;overflow:hiddenl">
<div style="width: 220px;display:block;">
<%# DataBinder.Eval(Container.DataItem, "Description").ToString().Replace("\n","<br/>").Replace("\r","<br/>")%>
</div>
</div>
0
 
GiftsonDJohnCommented:
Hi,

In textbox the wrap is done by a new line character (\r\n). But html doesn't understand the wrap by a new line char. It is doe by <br />. So you need to wrap by

<div style="widht:220px;display:block;overflow:hiddenl">
<%# DataBinder.Eval(Container.DataItem, "Description").ToString().Replace(Environment.NewLine,"<br/>")%>
</div>

In certain cases the above will not work. The replacement is below

<div style="widht:220px;display:block;overflow:hiddenl">
<%# DataBinder.Eval(Container.DataItem, "Description").ToString().Replace("\n","<br/>").Replace("\r","<br/>")%>
</div>
0
 
jbajajAuthor Commented:
yes GiftsonDJohn:

but when i replace /n by </br> breakline work but wrap will not work  so when i do this my div text will overflow i need this text should display in my fixed width div if text line increase it should come in next line

<div style="widht:220px;display:block;overflow:hiddenl">
<%# DataBinder.Eval(Container.DataItem, "Description").ToString().Replace("\n","<br/>").Replace("\r","<br/>")%>
</div>

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.