Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Eval for creating Comma Separated string from Generic list

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>
like image 834
LCJ Avatar asked Nov 17 '25 20:11

LCJ


2 Answers

You can use

<%#String.Join(",",((Report)Container.DataItem).DepartmentList)%>
like image 69
moskalevN Avatar answered Nov 20 '25 11:11

moskalevN


Try this

<ItemTemplate>
   <%# String.Join((List<string>)Eval("DepartmentList")).ToArray()) %>
</ItemTemplate>

Note: code not tested

like image 24
codingbiz Avatar answered Nov 20 '25 11:11

codingbiz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!