[英]Using Eval for creating Comma Separated string from Generic list
I have a Report class. 我有一个Report类。 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?
我们可以使用Eval将它作为逗号分隔列表在转发器中吗? If we cannot use Eval, is there any other syntax for this in repeater?
如果我们不能使用Eval,那么在转发器中是否还有其他语法?
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.NET标记
<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>
您可以使用
<%#String.Join(",",((Report)Container.DataItem).DepartmentList)%>
Try this 尝试这个
<ItemTemplate>
<%# String.Join((List<string>)Eval("DepartmentList")).ToArray()) %>
</ItemTemplate>
Note: code not tested 注意:代码未经过测试
In your class Report
, you may want to add an extra property 在您的课程
Report
,您可能想要添加额外的属性
public string DepartmentListCommas
{
get
{
return string.Join(", ", DepartmentList);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.