I have a Report class. The reports data is rendered using a repeater control. There is a department list (generic list of string) to be displayed as comma separated. Can we make it as a comma separated list in the repeater using Eval? If we cannot use Eval, is there any other syntax for this in repeater?
Class
public class Report
{
public int ReportID { get; set; }
public string Title { get; set; }
public string Recipients { get; set; }
public string Frequency { get; set; }
public List<string> DepartmentList { get; set; }
}
ASP.NET Markup
<asp:Repeater ID="rptReports" runat="server">
<HeaderTemplate>
<div>
</div>
</HeaderTemplate>
<ItemTemplate>
<div class="repeaterIdentifier">
<div class="reportTitle">
<%# Eval("Title") +":" %>
</div>
<div class="reportFrequency">
<%# " Frequency - "+ Eval("Frequency") %>
</div>
</div>
<div class="reportContent">
<div class="repeaterLine">
<%# Eval("Recipients")%></div>
</div>
</ItemTemplate>
</asp:Repeater>
You can use
<%#String.Join(",",((Report)Container.DataItem).DepartmentList)%>
Try this
<ItemTemplate>
<%# String.Join((List<string>)Eval("DepartmentList")).ToArray()) %>
</ItemTemplate>
Note: code not tested
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With