Link to home
Start Free TrialLog in
Avatar of jbajaj
jbajaj

asked on

"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
Avatar of GiftsonDJohn
GiftsonDJohn
Flag of India image

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>
Avatar of jbajaj
jbajaj

ASKER

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>

ASKER CERTIFIED SOLUTION
Avatar of GiftsonDJohn
GiftsonDJohn
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial