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

Posted on 2009-04-17
Last Modified: 2012-05-06
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")%>

please help me to solve this issue
Question by:jbajaj
    LVL 14

    Expert Comment


    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/>")%>

    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/>")%>

    Author Comment

    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/>")%>

    LVL 14

    Accepted Solution

    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/>")%>

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now