WebRef.eu  - Internet Marketing and Online Business Resources  

Home / Site Map | Blog | Contact

How to Display Line Breaks from MySql in a VB.net DataGrid

One of the issues we have encountered in displaying data from a MySql database in a VB.net DataGrid is that the line breaks are not being displayed. To fix this, you will need to switch off AutoGenerateColumns in your DataGrid, i.e.

<asp:datagrid id="dgItems" runat="server" AutoGenerateColumns="false">

Then, instead of using a standard BoundColumn, i.e.:

<asp:BoundColumn DataField="ItemDescription" HeaderText="Review Description"></asp:BoundColumn>

Change it to a TemplateColumn as follows:

<asp:TemplateColumn HeaderText="Review Details">
<ItemTemplate>
<%#Eval("ItemDescription").ToString.Replace(vbCrLf, "<br />")%>
</ItemTemplate>
</asp:TemplateColumn>

This should mean that where the line break character appears in your MySql database, it is replaced by the html linebreak character <br />.

Note, it might also be worth checking that your line break characters are being added in to your MySql database in the first place. Use MySql Query Browser to view your data. The below shows data containing four line break characters:

Added: 1-May-2007

 




Low Prices UK Shopping

Compare Prices
at LowPrices.co.uk


Home / Site Map | Contact

All Content ©2020 WebRef.eu