I’m currently having a problem in displaying some stuff in ListView. I have a normal C# Student class and a Classroom class. In Classroom class contains a List of Student classes which is shown below:
public class Classroom
{
int classroomid {set;get;}
List<Students> students{set;get;}
}
My question is if I bind my DataSource of the ListView to a List of objects of Classroom, how do I render the Student lists in the ListView?
<ListView>
<ItemTemplate>
<asp:Label Text='<%# Eval("classroomid") %>'></asp:Label>
<asp:Label Text='<%# Eval("students") %>'</asp:Label>
<asp:Label Text='<%# Eval("students.name") %>'</asp:Label>
</ItemTemplate>
</ListView>
The code above essentially explains that what I’m trying to achieve, or possibly displays the student’s details such as name or etc. Is there any way to achieve that? I do understand that nested ListView works, but I’m not sure how is the implementation.
Thank you for your help in advance. 🙂
You could use
string.Join:Edit: I missed that
Studentis a custom type. So you should better do this in the ListView’sItemDataBoundevent for readability.But it should work also on aspx:
in codebehind: