I have a list object
List<Documents>
, and inside that I have another list list of accounts.
List<Accounts>
From my codebehind I connect List to a repeater control
rptDocumentListings.DataSource = List<Documents>;
rptDocumentListings.DataBind();
While the repeater loops thru each item in List I want it to also loop thru each nest list of accounts, and then render out with
tags. Here is what I’ve tried so far:
//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;
}
The error I get is ‘Cannot convert from from ‘Object’ to ‘System.Collections.List’
Can someone please point me in the right direction? Thanks in advance.
Change
To
DataBinder.Eval returns an
Objectand your method expects aList<Account>.