我有一个列表对象
List<Documents>
,在其中我有另一个帐户列表。
List<Accounts>
从我的代码隐藏中,我将 List 连接到中继器控件
rptDocumentListings.DataSource = List<Documents>;
rptDocumentListings.DataBind();
虽然中继器循环遍历 List 中的每个项目,但我希望它也循环遍历每个嵌套的帐户列表,然后使用
标签呈现。这是我迄今为止尝试过的:
//in the dataRepeater
<%# parseAccountNumbers(Eval("Accounts"))%>
//method in codebehind
public string parseAccountNumbers(List<Account> accounts)
{
string allAccounts = string.Empty;
foreach (var item in accounts)
{
allAccounts += string.Format("{0}<br />", item.AccountNumber);
}
return allAccounts;
}
我得到的错误是'无法从'对象'转换为'System.Collections.List'有人可以指出我正确的方向吗?提前致谢。