Can anybody give me some tips on the easiest way to insert multiple lines in to database and retrieve the same multiple lines from database to gridview.The data displays on a single line. Is there any way to display multiple lines???
Hello,
If you insert multi line text from TextBox ( with TextMode="MultiLine"), it will insert "\r\n" for line breaks. That will be stored in DB also. Now if you want to display that in different lines in GridView, you need to replace those charecters "\r\n" with
"<br />".
That you can do in RowDataBound event of GridView or you can do in your SQL query also.
Why you should save string in DB in multiple lines. If you store a very long string in Db, When you retrieve it, it will be displayed in mutilline if the width of the lable/multiline textbox is not sufficient to display the full string in a single line.
No special arrangements necessary ..
basheerkal
Kindly mark this post as "Answer", if it helped you.
Yes, indeed I think you can format your Text outputed by <p>...</p> (e.g: Suppose you want to add a new line at the end of each sentance with the mark ".", you can try like this):
1) First design your GridView like this:
<asp:GridView ...>
<asp:Template>
<ItemTemplate>
<%#FormationNow(Eval("TextContents"))%>
</ItemTemplate>
</asp:Template>
</asp:GridView>
2) Then write a protected function like this below in the cs file mapping to your aspx page in your project:
udayb99
Member
4 Points
15 Posts
Display multiple lines in field of gridview
Sep 07, 2009 01:21 PM|LINK
Hi
Can anybody give me some tips on the easiest way to insert multiple lines in to database and retrieve the same multiple lines from database to gridview.The data displays on a single line. Is there any way to display multiple lines???
ShailAtlas
Contributor
2269 Points
548 Posts
Re: Display multiple lines in field of gridview
Sep 07, 2009 01:36 PM|LINK
Hello,
If you insert multi line text from TextBox ( with TextMode="MultiLine"), it will insert "\r\n" for line breaks. That will be stored in DB also. Now if you want to display that in different lines in GridView, you need to replace those charecters "\r\n" with "<br />".
That you can do in RowDataBound event of GridView or you can do in your SQL query also.
Thanks
Shail
basheerkal
Star
10672 Points
2426 Posts
Re: Display multiple lines in field of gridview
Sep 07, 2009 02:16 PM|LINK
Hi,
Why you should save string in DB in multiple lines. If you store a very long string in Db, When you retrieve it, it will be displayed in mutilline if the width of the lable/multiline textbox is not sufficient to display the full string in a single line. No special arrangements necessary ..
basheerkal
(Talk less..Work more)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Display multiple lines in field of gridview
Sep 11, 2009 01:23 AM|LINK
Yes, indeed I think you can format your Text outputed by <p>...</p> (e.g: Suppose you want to add a new line at the end of each sentance with the mark ".", you can try like this):
1) First design your GridView like this:
<asp:GridView ...>
<asp:Template>
<ItemTemplate>
<%#FormationNow(Eval("TextContents"))%>
</ItemTemplate>
</asp:Template>
</asp:GridView>
2) Then write a protected function like this below in the cs file mapping to your aspx page in your project:
protected string FormationNow(object contents)
{
return contents.Replace(".",".</p>");
}
Notes: Words meeting with "</p>" these HTML singals will be reguared as HTML symbols until you use Html.Encoding() function.