gridview text displayhttp://forums.asp.net/t/1109803.aspx/1?gridview+text+displayMon, 14 May 2007 16:59:14 -040011098031706581http://forums.asp.net/p/1109803/1706581.aspx/1?gridview+text+displaygridview text display <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">Hi,</font></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">&nbsp;</font></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">Im still very new to asp and c#.</font></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">&nbsp;</font></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">I want to display comments from a multi line textbox in a gridview.</font></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">&nbsp;</font></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">I can do this using a template and multi line textbox but it looks poor.</font></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">&nbsp;</font></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">Is there a way to display the text in the grid view so that it displays text similar to the way the comments work on this forum or should I move away from the gridview and try databinding</font></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">&nbsp;</font></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">&nbsp;</font></p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">many thanks </font> </p> <p class="MsoNormal" style="margin:0cm 0cm 0pt"><font size="3">&nbsp;</font></p> <span style="font-size:12pt; font-family:Arial">jimmy</span> 2007-05-12T00:20:17-04:001706586http://forums.asp.net/p/1109803/1706586.aspx/1?Re+gridview+text+displayRe: gridview text display <p>when displaying the data, i'd use a label or a literal control and not a multiline textbox.&nbsp; if the data was entered from a multiline textbox, you'll likely need to deal with the fact the the data might have CRLF characters that don't render. in this case, i would simply replace those characters with a &lt;br /&gt; tag.</p> <p>check this for a sample: <a href="http://forums.asp.net/thread/1515605.aspx">http://forums.asp.net/thread/1515605.aspx</a></p> <p>&nbsp;</p> 2007-05-12T00:34:35-04:001706987http://forums.asp.net/p/1109803/1706987.aspx/1?Re+gridview+text+displayRe: gridview text display <p>Hi</p> <p>&nbsp;Thanks but it still does not solve my problem. i am using a datagrid at the moment and want to display text in a way similar to the way this forum works. should i move away from the datagrid and use a dataset instead. i would have used this method in php.</p> <p>or is there a way to&nbsp;display multiline text neatly into a datagrid.</p> <p>thanks</p> <p>jimmy</p> 2007-05-12T20:56:56-04:001706989http://forums.asp.net/p/1109803/1706989.aspx/1?Re+gridview+text+displayRe: gridview text display <p>text received from a regular multiline textbox will contain crlf characters.&nbsp; in order to display that text (like this forum does) the line breaks need to be converted to &lt;br /&gt; tags.</p> <p>the idea of moving from a datagrid to a dataset won't work since a datagrid is a UI control and a&nbsp;dataset in not a&nbsp;UI control.&nbsp; they are not at all interchangeable. The simpleset was to display multiline text in a gridview / datagrid is to replace the crlf sequences with &lt;br /&gt; tags.</p> <p>if you use a rich html editor control like freetextbox or tinymce (like i think this forum does), then it would give you your multiline text as an html fragment that already uses &lt;br /&gt; tags and not CRLF's.</p> <p>&nbsp;</p> 2007-05-12T21:07:17-04:001706998http://forums.asp.net/p/1109803/1706998.aspx/1?Re+gridview+text+displayRe: gridview text display <p>thanks for bearing with me.</p> <p>i understand replacing&nbsp; crlf characters with&nbsp;&lt;br /&gt; tags. </p> <p>i can get data to be displayed in a multiline text box within a datagrid however it looks rubbish with my understanding of asp and c# so far.</p> <p>the textbox is of a fixed size and has scroll bars on it. &nbsp;this size textbox is the same for all rows in the data grid and&nbsp;does not respond to the amount of text displayed.&nbsp;</p> <p>thanks</p> <p>jimmy</p> <p>&nbsp;</p> 2007-05-12T21:41:42-04:001707007http://forums.asp.net/p/1109803/1707007.aspx/1?Re+gridview+text+displayRe: gridview text display <p>the textbox should only be used to collect/edit the data.&nbsp; </p> <p>when presenting/displaying the data, i would recommend using either a Literal control or a Label control in your grid controls template.&nbsp; you would bind your multiline data to the text property of this Literal/Label.&nbsp; Then, as long as you have converted the crlfs, your display should look much better.</p> <p>&nbsp;</p> 2007-05-12T22:08:15-04:001707521http://forums.asp.net/p/1109803/1707521.aspx/1?Re+gridview+text+displayRe: gridview text display <p>thanks for you help. </p> <p>i have used a label now and ive got the look i want. i am having a some trouble with the <font size="2">FixCrLf&nbsp; function.</font></p> <p><font size="2">i get an error saying </font></p> <p><font size="2">&nbsp;CS1502: The best overloaded method match for 'Default2.FixCrLf(string)' has some invalid arguments</font></p> <p><font color="#ff0000">&lt;asp:Label ID=&quot;Label2&quot; runat=&quot;server&quot; Text='&lt;%# FixCrLf(Eval(&quot;PostContent&quot;)) %&gt;'&gt; &lt;/asp:Label&gt;<br> </font></p> <p><font size="2">&nbsp;i am using c# and have used the following in my application</font></p> <p><font size="2"><font size="2">&nbsp;</p> <p></font><font color="#0000ff" size="2">protected</font><font size="2"> </font><font color="#0000ff" size="2">string</font><font size="2"> FixCrLf(</font><font color="#0000ff" size="2">string</font><font size="2"> value) { </p> <p></font><font color="#0000ff" size="2">if</font><font size="2"> (</font><font color="#0000ff" size="2">string</font><font size="2">.IsNullOrEmpty(value)) </font><font size="2">{ </p> <p></font><font color="#0000ff" size="2">return</font><font size="2"> </font><font color="#0000ff" size="2">string</font><font size="2">.Empty; </p> <p>} </p> <p></font><font color="#0000ff" size="2">return</font><font size="2"> value.Replace(</font><font color="#2b91af" size="2">Environment</font><font size="2">.NewLine, </font><font color="#a31515" size="2">&quot;&lt;br /&gt;&quot;</font><font size="2">); </p> <p>}</p> </font></font> <p><font size="2"><font color="#ff0000" size="2">&nbsp;</p> <p>Text</font><font color="#0000ff" size="2">='</font><font size="2">&lt;%# FixCrLf(Eval(&quot;PostContent&quot;)) %&gt;</font><font color="#0000ff" size="2">'&nbsp;&nbsp; this line shows cannot convert object to string in the VS error list</font></p> <p><font color="#0000ff" size="2"></font><font color="#0000ff" size="2">thanks again for your help</p> </font></font> <p><font size="2">&nbsp;jimmy</font></p> <p><font size="2">&nbsp;</p> </font> 2007-05-14T01:16:18-04:001708097http://forums.asp.net/p/1109803/1708097.aspx/1?Re+gridview+text+displayRe: gridview text display <p>The Eval method you are using returns an object.&nbsp; To get Eval to return a String, you can&nbsp;use&nbsp;its overload that allows you to specify a formatstring.&nbsp; When a formatstring is specified (even if its just an empty string&nbsp;&quot;&quot;) the Eval method will return a String and not an object.</p> <p>like this:</p> <pre class="prettyprint">&lt;asp:Label ID=&quot;Label2&quot; runat=&quot;server&quot; Text='&lt;%# FixCrLf(Eval(&quot;PostContent&quot;,&quot;&quot;)) %&gt;'&gt; &lt;/asp:Label&gt;</pre>&nbsp;&nbsp; <p>&nbsp;</p> 2007-05-14T10:28:22-04:001708635http://forums.asp.net/p/1109803/1708635.aspx/1?Re+gridview+text+displayRe: gridview text display <p>Hi</p> <p>Thanks for all your help. That has worked a treat.</p> <p>&nbsp;</p> <p>jimmy</p> 2007-05-14T16:59:14-04:00