Search code examples
repeaterseparator

How to separate data items in Repeater?


I'm using a Repeater

<asp:Repeater runat="server" ID="rpt">
    <ItemTemplate>
        <asp:Label  Text='<%# Eval("History_Info") %>'</asp:Label>
    </ItemTemplate>
</asp:Repeater> 

The results that I get from DataSource are list of strings.

ex: Date:08/07/2014, User: UserName, LoginNumber: 000 ......

How can I show it like that :

Date: 08/07/2014

User: UserName

LoginNumber: 000

Thanks


Solution

  • Try doing a replace during binding, so that commas are replaced with line breaks, like so:

    <asp:Label  Text='<%# ((string)Eval("History_Info")).Replace(",", @"<br/>") %>'</asp:Label>
    

    This will throw error if History_Info is null, so you need to handle that as well, perhaps by using null-coalescing operator (??) or an explicit check.