I have a SQL database and there I have a text with line breaks. But in the repeater the text has no breaks. Is there a solution, that the repeater takes the breaks?
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td></td>
<td colspan="2" style="text-align:center"><%# Eval ("Titel") %></td>
</tr>
<tr>
<td><asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("Bild") %>' /></td>
<td><%# Eval ("Inhalt") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
The issue most likely is that the line breaks are stored as line breaks used in the OS environment (such as Environment.NewLine). Those line breaks are not shown as such in HTML.
You need to replace them with the HTML line break, <br />
, in your repeater code:
<td><%# ((string)Eval ("Inhalt")).Replace(Environment.NewLine, "<br />") %></td>
Of course this would look much nicer if you prepared the data in code-behind using a view model, but alas, it works.