Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of a trailing comma using ASP.NET Repeater?

Tags:

asp.net

Working on VS 2010 C# ASP.NET and SQL Server 2008 R2

I'm using a repeater to retrieve data from the SQL server.

I would like to separate values with a comma.

my code is:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="ConnectionString">
    <ItemTemplate>
        <%# Eval("DataValue").ToString() %>, 
    </ItemTemplate>
</asp:Repeater>

I get:

1, 2, 3,

While I don't want the trailing comma and get:

1, 2, 3

What is the best practice to get rid of the trailing comma?

like image 852
elarrow Avatar asked Aug 14 '12 21:08

elarrow


1 Answers

You could try using a separator:

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="ConnectionString">
    <ItemTemplate><%# Eval("DataValue").ToString() %></ItemTemplate>
    <SeparatorTemplate>, </SeparatorTemplate>
</asp:Repeater>

You may need to be careful with spacing to get it to work properly.

like image 176
Richard Avatar answered Sep 28 '22 00:09

Richard